Send transactions
📋Prerequisites
- Setup
- Login
- Initialise provider and connect wallet
- The zkEVM send transaction feature requires pre-approved transactions to be enabled. Please follow the guide here for instructions on how to enable this feature.
💡Note
Games can only use ERC-20 tokens issued by the game itself, meaning currencies like ETH, USDC, IMX, USDT, etc. cannot be used in-game.
to
: The destination addressvalue
: The value to transfer for the transaction in weidata
: Byte string containing the associated data of the message
This method does not support the gas
, gasPrice
, maxPriorityFeePerGas
, or maxFeePerGas
properties as the relayer abstracts these away from the user.
Additionally, the from
property is not supported as the user's Passport wallet address is used instead.
- (Recommended) With Confirmation
- Without Confirmation
Sends a transaction to the network, signs it using the logged-in Passport account, and waits for the transaction to be included in a block.
using Immutable.Passport.Model;
TransactionRequest request = new TransactionRequest()
{
to = address,
value = amount,
data = data
}
TransactionReceiptResponse response = await passport.ZkEvmSendTransactionWithConfirmation(request);
switch (response.status)
{
case "1":
// Successful
break;
case "0":
// Failed
break;
}
Sends a transaction to the network and signs it using the logged-in Passport account.
using Immutable.Passport.Model;
TransactionRequest request = new TransactionRequest()
{
to = address,
value = amount,
data = data
}
string transactionHash = await passport.ZkEvmSendTransaction(request);
⚠️Warning
It's important to note that obtaining the transaction hash does not guarantee a successful transaction. To determine the transaction's status, use
ZkEvmGetTransactionReceipt
along with the transaction hash received.As an example:
using System.Threading;
using Cysharp.Threading.Tasks;
async void GetTransactionReceiptStatus()
{
string? status = await PollStatus(
passport,
transactionHash,
TimeSpan.FromSeconds(1), // Poll every one second
TimeSpan.FromSeconds(10) // Stop polling after 10 seconds
);
switch (status)
{
case "0x1":
// Successful
break;
case "0x0":
// Failed
break;
}
}
static async UniTask<string?> PollStatus(Passport passport, string transactionHash, TimeSpan pollInterval, TimeSpan timeout)
{
var cancellationTokenSource = new CancellationTokenSource(timeout);
try
{
while (!cancellationTokenSource.Token.IsCancellationRequested)
{
TransactionReceiptResponse response = await passport.ZkEvmGetTransactionReceipt(transactionHash);
if (response.status == null)
{
// The transaction is still being processed, poll for status again
await UniTask.Delay(delayTimeSpan: pollInterval, cancellationToken: cancellationTokenSource.Token);
}
else
{
return response.status;
}
}
}
catch (OperationCanceledException)
{
// Task was canceled due to timeout
}
return null; // Timeout or could not get transaction receipt
}
💡Tip
It is recommended that you follow best practices for client-side polling, including setting maximum attempts, polling intervals, and knowing when to pause or resume polling.
See here for more details.