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)
.
- Web
- Flutter
const tokenAddress = "YOUR_TOKEN";
const tokenDecimals = 18;
const to = "RECEIVER_ADDRESS";
const amount = ethers.parseUnits("0.001", tokenDecimals);
const data = Uint8Array.from([]);
await fuseSDK.transferToken(tokenAddress, to, amount, data, {
useNonceSequence: true,
});
await fuseSDK.transferToken(tokenAddress, to, amount, data, {
useNonceSequence: true,
customNonceKey: 231,
});
// 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),
),
);