docs2 icon indicating copy to clipboard operation
docs2 copied to clipboard

Understanding Mina transactions - getter function

Open Pfed-prog opened this issue 1 year ago • 1 comments

Gm, I am trying to understand how to get a value back from a contract

const txn = await Mina.transaction(deployerAddress, () => {
  contract.balanceOf(deployerAddress);
});
await txn.prove();
await txn.sign([deployerAccount]).send();

The function in an ideal case would provide an ability to read the data the contract returns.

However the best i could get is call txn.toPretty()

which returns a large json with the correct values hidden in preconditions image

Pfed-prog avatar Jan 07 '24 17:01 Pfed-prog

I have further dug into the available code and tutorials

I think the key issue has been so far that not many of the examples work on an actual testnet

Hence, the following coding pattern from the docs is missed - https://docs.minaprotocol.com/zkapps/o1js/interact-with-mina

// send transaction, log transaction hash
let pendingTx = await tx.send();
console.log(`Got pending transaction with hash ${pendingTx.hash()}`);

// wait until transaction is included in a block
await pendingTx.wait();

// our account updates are applied on chain!

Pfed-prog avatar Jan 08 '24 16:01 Pfed-prog