Skip to main content

Non-Blocking Transactions

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).

Example approve_and_transfer.dart

// Approve and transfer
final tokenAddress = EthereumAddress.fromHex('TOKEN_ADDRESS');
final recipientAddress = EthereumAddress.fromHex('RECIPIENT_ADDRESS');
final amountInWei = BigInt.parse('AMOUNT_IN_WEI');

final res = await fuseSDK.executeBatch(
[
// Approve ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20ApproveCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
// Transfer ERC20 Token call
Call(
to: tokenAddress,
value: BigInt.zero,
data: ContractsUtils.encodeERC20TransferCall(
tokenAddress,
recipientAddress,
amountInWei,
),
),
],
FuseSDK.defaultTxOptions.copyWith(
useNonceSequence: true,
customNonceKey: BigInt.from(11),
),
);

// Transfer
await fuseSDK.transferToken(
EthereumAddress.fromHex('TOKEN_ADDRESS'),
EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
BigInt.parse('AMOUNT_IN_WEI'),
FuseSDK.defaultTxOptions.copyWith(
useNonceSequence: true,
customNonceKey: BigInt.from(12),
),
);

// Transfer
await fuseSDK.transferToken(
EthereumAddress.fromHex('TOKEN_ADDRESS'),
EthereumAddress.fromHex('RECIPIENT_ADDRESS'),
BigInt.parse('AMOUNT_IN_WEI'),
FuseSDK.defaultTxOptions.copyWith(
useNonceSequence: true,
customNonceKey: BigInt.from(34234),
),
);

Code example

For more code examples on using the Fuse Wallet SDK for Flutter for Batch Transfer, you can check out the official Flutter SDK repository.

Was this page helpful?