Skip to main content

Non-Blocking Transactions

For Developers who want to build use cases that require a higher throughput, then 2D nonces are essential. For example: A user may want to make four independent transactions. With only a 1D nonce, a user would have to wait for each transaction to get on-chain before sending the next one to the mempool. In Non-Blocking such a user can build each User Operation using nonces from keys 0, 1, 2, and 3. All four transactions can then be submitted at once without blocking each other. This can be an approve, unstake, withdraw and transfer transaction in one User Operation. The executeBatch() method is used.

To utilize this feature, simply pass the TxOptions with useNonceSequence: true. Setting this flag activates the NonceManager, which increments the nonce automatically. Additionally, you have the option to pass a custom nonce key, for example, customNonceKey: BigInt.from(10).

const approveCallData = ContractUtils.encodeERC20ApproveCall(
spender,
amount
) as unknown as Uint8Array;

const calls = [
{
to: tokenAddress,
value: BigInt(0),
data: approveCallData,
},
{
to: spender,
value: BigInt(0),
data: callData,
},
{
useNonceSequence: true,
customNonceKey: 100,
}
];

const res = await fuseSDK.executeBatch(calls, txOptions);
console.log(`UserOpHash: ${res?.userOpHash}`);
console.log('Waiting for transaction...');

const receipt = await res?.wait();
console.log('Transaction Hash:', receipt?.transactionHash);