Transfer ERC721 Tokens

import 'dotenv/config';
import { NetworkNames, initializeSdkGateway } from '@kanalabs/mirai';

const collectionAddress = '0xc2132D05D31c914a87C6611C10748AEb04B58e8F'; // Sender address
const receiverAddress = '0x97a57d9CE2889E2E8DFb6019f8Eb51F5d119Bde3'; // Receiver address

(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);

    // get address of KanaWallet
    const sender = await networkInstance.getCounterFactualAddress();

    //initialize erc721 sdk instance
    const erc721 = sdk.erc721(collectionAddress);

    // clear any previous transactions in batch
    await networkInstance.clearUserOpsFromBatch();

    // add erc721 transferFrom function to the batch
    await erc721.transferFrom(sender, receiverAddress, 10);

    // estimate transactions added to the batch and get the fee data for the UserOp
    const op = await networkInstance.estimate();

    // sign the UserOp and sending to the bundler...
    const uoHash = await networkInstance.send(op);

    // log the uoHash
    console.log(`UserOpHash: ${uoHash}`);
})()

Last updated