Sending Batch Transaction (using telegram)
Step 1: Creating the Batch Transaction
After initializing the SDK, you can create an array of batch transactions using the BatchUserOperationCallData
interface. This array represents the transactions you want to send. Here's an example:
In this code:
We import the
UserOperationCallData
interface to define the structure of the transaction object.transactions
is an object that contains the transactions withtarget
(recipient's Ethereum address),data
(transaction data in hexadecimal format), and an optionalvalue
field for the transaction amount in wei.
Step 2: Prepare UserOperation and Send OTP on User's Telegram
Now that you have the transactions array, to send userOp there are 2 steps.
Prepare UserOp and send OTP on telegram to user:
First, call prepareUserOpBatch
function on SDK with transactions as an argument to it. It will return with OTP sent status as success: true/false
and requestId
.
User will receive OTP on telegram which has to be sent in next step. Implement functionality to get the OTP from user as per your choice.
In this code:
sendUserOp
takes 2 arguments: requestId and OTP.The
await client.sendUserOp(requestId, otp)
call sends the requestId and OTP and returns an object containing both theuserOpHash
andtransactionHash
.The
userOpHash
is the hash of the user operation, and transactionHash is the hash of the underlying transaction.Both hashes are logged to the console for your reference.
With these steps, you can successfully send a transaction using Telegram and capture both the user operation hash and the transaction hash using the 0xGasless AA SDK.
Last updated