Transfer Native Tokens
import { utils } from 'ethers';
import 'dotenv/config';
import { NetworkNames, initializeSdkGateway } from '@kanalabs/mirai';
import { sleep } from '@etherspot/prime-sdk/dist/sdk/common';
const receiverAddress = '0x97a57d9CE2889E2E8DFb6019f8Eb51F5d119Bde3'; // Receiver address
const value = '0.01';
(async () => {
// initializating sdk...
const sdk = await initializeSdkGateway(
{ privateKey: process.env.PRIVATE_KEY as string },
{
networks: [NetworkNames.Mumbai],
bundlerApiKey: process.env.BUNDLER_API_KEY
},
);
// set mumbai as default current instance
const networkInstance = sdk.setCurrentInstance(NetworkNames.Mumbai);
// clear the transaction batch
await networkInstance.clearUserOpsFromBatch();
// add transactions to the batch
await networkInstance.addUserOpsToBatch({ to: receiverAddress, value: utils.parseEther(value) });
// estimate transactions added to the batch and get the fee data for the UserOp
const op = await networkInstance.estimate();
console.log("op: ", op);
// sign the UserOp and sending to the bundler...
const uoHash = await networkInstance.send(op);
// log the uoHash
console.log(`UserOpHash: ${uoHash}`)
let userOpsReceipt = null;
const timeout = Date.now() + 60000 // 1 minute timeout
while (userOpsReceipt == null && Date.now() < timeout) {
await sleep(2)
userOpsReceipt = await networkInstance.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
})()
Last updated