Notus API
Gasless & Transaction Abstraction

Send Your First Transaction

How to transfer crypto tokens using the Notus API

This guide explains how to transfer crypto tokens using the Notus API. You will set up a wallet, generate a transfer request, and execute the transfer.

1. Initialize Wallet Account

First, use your private key to initialize a wallet account. This allows you to sign messages and interact with the blockchain

import { privateKeyToAccount } from 'viem/accounts';
 
const BRZ_POLYGON = '0x4eD141110F6EeeAbA9A1df36d8c26f684d2475Dc';
const USDC_POLYGON = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359';
 
const privKey = '0x<private-key>'; // Replace <private-key> with your private key
const account = privateKeyToAccount(privKey);

2. Get Smart Wallet Address

Before transferring tokens, you need to register and retrieve the smart wallet address for Account Abstraction.

const getSmartWalletAddress = async () => {
  const FACTORY_ADDRESS = "0x0000000000400CdFef5E2714E63d8040b700BC24";
  let res = await fetch(`https://<baseUrl>/api/v1/wallets/register`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "x-api-key": "<api-key>",
    },
    body: JSON.stringify({
      externallyOwnedAccount: externallyOwnedAccount,
      factory: FACTORY_ADDRESS,
      salt: "0",
    }),
  });
 
  if (!res?.ok) {
    return
  }
 
  const data = await res.json();
  setAccountAbstraction(data.wallet.accountAbstraction);
};

3. Create Transfer Parameters

Define the parameters for your transfer, specifying the token, amount, sender's address, and recipient's address.

const transferParams = {
  payGasFeeToken: USDC_POLYGON, // Token used to pay gas fees
  token: BRZ_POLYGON,        // Token to transfer
  amount: '2',               // Amount to transfer
  walletAddress: '0x9Ea7DbDA009D6fDeb0AEbF82c62F3CDC4A947098', // Sender's wallet
  signerAddress: account.address, // Signer's address
  toAddress: '0x<recipient-address>', // Replace <recipient-address> with the recipient's wallet
  chain: 'POLYGON',          // Blockchain network
  gasFeePaymentMethod: 'DEDUCT_FROM_AMOUNT', // Fee payment method
};

4. Request Transfer

Send the transfer request to the Notus API to get a quote for executing the transfer.

const { data } = await fetch('http://<baseUrl>/api/v1/crypto/transfer', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': '<api-key>', // Replace <api-key> with your API key
  },
  body: JSON.stringify(transferParams),
}).then((res) => res.json());

5. Execute Transfer

Sign the transfer quote and execute the transfer using the Notus API.

const signature = await account.signMessage({
  message: {
    raw: data.quoteId, // Quote ID from the transfer quote
  },
});
 
const res = await fetch('http://<baseUrl>/api/v1/crypto/execute-user-op', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': '<api-key>', // Replace <api-key> with your API key
  },
  body: JSON.stringify({ signature, quoteId: data.quoteId }),
}).then((res) => res.json());
 
console.log('Transfer Result:', res);

On this page