JS SDK contract object - concurrent calls?

Is it possible to use concurrent smart contract method calls using the contract object? This seems not to work, ie calling the same method again, before the previous call has been mined. I assume nonce is not increased in that case?

Dry-Running (Static-Call) is possible by default if you don’t await the result. Calling as Transaction is possible if you manually set the nonce with your call.

Tnx Piwo! Will try it out. Btw could you give an example of manually setting the nonce if it’s not a problem? I don’t remember I have seen it in the docs

Also, nonce is tied just to the caller or caller AND the method being called?

Nonce is just tied to the caller (i.e. the account signing the call transaction).

@philipp.chain is there a function to get the current account nonce? Secondly, could you give me an example of specifying the nonce using the contract object? I can only find documentation about specifying the nonce when using the tx builder

Hey @CryptoTask,

I didn’t have a look at the documentation, but my IDE (Webstorm) helps me find the needed apis, maybe @nduchak.chain can link the correct documentation.

An example here (although rarely I run in invalidtx and don’t know why)

    const contractSouce = `
@compiler >= 4

contract Example =
  type state = int
  entrypoint init() = 0
  stateful entrypoint set(x : int) = put(x)
  entrypoint get() = state`;

    const contract = await client.getContractInstance(contractSouce);
    await contract.deploy();

    const nonce = (await client.getAccount("ak_2VnwoJPQgrXvreUx2L9BVvd9BidWwpu1ASKK1AMre21soEgpRT")).nonce;

    [...Array(50).keys()].reduce(async (acc, i) => {
        await acc;
        const nextNonce = nonce + 1 + i;
        console.log(nonce, nextNonce);

        await contract.methods.set(i, {nonce: nextNonce, waitMined: false});
    }, Promise.resolve());

Thanks, I’ll give it a go! :slight_smile:

2 Likes