o1-labs / docs2

Docs website for the Mina Protocol.
https://docs.minaprotocol.com
74 stars 110 forks source link

Understanding Mina transactions - getter function #791

Open Pfed-prog opened 6 months ago

Pfed-prog commented 6 months ago

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 commented 6 months ago

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!