Send transactions

Applications can request to send NEAR, sign and send a single transaction, or a batch of transactions

Sign and send a single transaction to a smart contract

Applications can call signAndSendTransaction API with the following API signature:

signAndSendTransaction: ( params: SignAndSendTransactionParams ) 
    => Promise<SignAndSendTransactionResponse>

export interface Action {
  methodName: string;
  args: object;
  gas: string;
  deposit: string;
}

export interface SignAndSendTransactionParams {
  receiverId: string;
  actions: Array<Action>;
}


//example transaction
let txExecution = 
    await window.nearFiWallet
      .signAndSendTransaction({
        receiverId: "usdc.fakes.testnet",
        actions: [
          {
            methodName: "storage_deposit",
            args: {accountId: "nearfi.testnet"},
            gas: parseNearAmount('0.02'),
            deposit: parseNearAmount('0.00125')
          }
        ]
      })
                              

NearFi wallet browser will show a popup to let users confirm the transaction.

A transaction can consist of multiple actions that call methods of the receiverId contract.

Sign and send a batch of transactions

Similar to the signAndSendTransaction API, applications can call requestSignTransactions API to send a batch of transactions each of which could call functions of different contracts:

//example transaction
let txExecution = 
    await window.nearFiWallet
      .requestSignTransactions([
        {
          receiverId: "naistable.deganstable.testnet",
          actions: [
            {
              methodName: "storage_deposit",
              args: {},
              gas: parseNearAmount('0.02'),
              deposit: parseNearAmount('0.1')
            }
          ]
        },
        {
          receiverId: "wrap.testnet",
          actions: [
            {
              methodName: "storage_deposit",
              args: {},
              gas: parseNearAmount('0.05'),
              deposit: parseNearAmount('0.00125')
            }
          ]
        },
        {
          receiverId: "naistable.deganstable.testnet",
          actions: [
            {
              methodName: "borrow",
              args: {borrow_amount: "200000000000000000000"},
              gas: parseNearAmount('0.02'),
              deposit: parseNearAmount('10')
            }
          ]
        },
      ])
                              

NearFi wallet browser will show a popup to let users confirm the transaction.

Send NEAR

Applications can also request to send NEAR to an accountId or a contract using sendMoney API.

//example transaction
let txExecution = 
    await window.nearFiWallet
      .sendMoney({
        receiverId: "nearfi.testnet",
        amount: parseNearAmount(20)
      })

Last updated