docs2
docs2 copied to clipboard
Understanding Mina transactions - getter function
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
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!