Kana Labs
  • Getting Started
    • Welcome to Kana Labs
  • CROSS CHAIN SWAPS
    • AMM DEX Aggregator
  • INTEGRATE KANA WIDGET
    • Kana Widget
      • Install Widget
      • Configure Widget
      • Configure Aptos Keyless
  • Web3 Aggregator SDK
    • Web3 Aggregator SDK
      • Installation
      • SameChain
      • Cross Chain Swap
      • Aggregator API's
  • SPOT TRADING PLATFORM
    • Kana Trade
      • API Docs
  • PERPETUAL FUTURES
    • Kana Perps
      • Getting Started
        • Mint Tokens on Testnet
        • Mainnet Tutorials
          • Getting Started
          • Connecting Wallet & Enabling “One Click Transaction”
          • Deposit & Withdraw Tokens
          • Placing a Market Trade Order
          • Placing a Limit Trade Order
          • Partially & Fully Closing a Live Trade Order
          • Adding Margin to an Open Position
          • Defining Take Profit & Stop Loss
      • Breaking Down Kana Perps
        • Assets Supported
        • Order Types
        • Orderbook
        • 1-Click Trading in Kana Perps
          • Delegation
        • Funding Rate
        • Leverage
        • Margin and Liquidation
        • Hedge Mode
          • Hedging a Short-Term 2-3% Price Decline
          • Dual Positioning for Flexible Profit-Taking
        • Trading Fees
      • Technical Architecture
      • API Docs
        • Installation Setup
        • Kana Perps Typescript REST API
        • Kana Perps Python Websocket API
        • Kana Perps Python REST API
        • Steps to place an order
        • Perps Contract Error Codes
        • Websocket Connection
        • Supported Markets
  • SPOT & PERP APIs
    • Trading APIs
      • Kana Trade API
      • Kana Perps API
        • Installation Setup
        • Example setup functions
        • Kana Perps Typescript REST API
        • Kana Perps Websocket API
        • Kana Perps Python Websocket API
        • Kana Perps Python REST API
        • Steps to place an order
  • PAYMASTER SERVICE
    • Kana Paymaster For Aptos and Supra
      • How it works?
      • How to Register?
      • Deposit Allowance
      • Manage Users
      • Paymaster SDK Tutorial (Typescript)
      • Paymaster API
      • Module & Function Whitelist
      • Subscription - Coming soon
      • FAQS
  • PERPETUAL OPTIONS
    • OPerps
  • Tokenomics & Governance
    • Kana Labs Tokenomics
  • REWARDS & REFERRAL PROGRAM
    • Rewards Program
      • Reward Program Season 1
      • Reward Program Season 2
      • How to Keep Track of Your Points?
      • Where to find the Missions Dashboard?
  • Referral Program
    • How to Generate Referral Link? (For the Referrer)
    • How to map your wallet to the invite IDs? (For the invited users)
Powered by GitBook
On this page
  1. Smart Wallet SDK
  2. Mirai SDK - The EVM Smart Wallet & Paymaster
  3. Paymaster

Sponsor Transactions

Using this API call we sponsor a transactions.

To sponsor a transaction, you need to whitelist the address beforehand.

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.0001';

(async () => {

    // initializating sdk...
    const sdk = await initializeSdkGateway(
        { privateKey: process.env.PRIVATE_KEY as string },
        {
            networks: [NetworkNames.Mumbai],
            bundlerApiKey: process.env.BUNDLER_API_KEY
        },
    );
    
    // Retrieve the chainId corresponding to the network name
    const chainId = networkNameToChainId(NetworkNames.Mumbai)

    // 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) });
    
    // get balance of the account address
    const balance = await networkInstance.getNativeBalance();
    console.log('balances: ', balance);

    // Estimate transaction details using paymaster for sponsorship mode.
    const op = await networkInstance.estimate({
        paymasterDetails: {
            url: `https://evm-paymaster.kanalabs.io?apiKey=${process.env.PAYMASTER_API_KEY}&chainId=${chainId}`,
            context: { mode: 'sponsor' },
        },
    });
    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);
})()
 * PAYMASTER_API_KEY - Contact kanalabs to obtain the API key for authentication.

Last updated 1 year ago