@near-snap/plugin

v0.6.0
View and sign transactions for NEAR Protocol

NEAR Protocol Snap

View and sign transactions for NEAR Protocol blockhain network

Get NEAR Account

await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: defaultSnapOrigin,
    request: {
      method: 'near_getAccount',
      params: { network: 'mainnet' } // testnet
    },
  },
});

// Result
{ accountId: "e270b...c4dc6a", publicKey: "ed25519:GEvqvr..." }

Sign transactions

// Like wallet-selector format transactions
const transactions = [
  {
    nonce: 1000,
    recentBlockHash: 'block_hash',
    receiverId: 'herewallet.near',
    actions: [
      {
        type: 'FunctionCall',
        params: {
          methodName: 'method',
          args: { arg1: '123' },
          gas: 500000000,
          deposit: '3000000',
        },
      },
    ],
  },
];

await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: defaultSnapOrigin,
    request: {
      method: 'near_signTransactions',
      params: { network: 'mainnet', transactions },
    },
  },
})[
  // Result, null if transaction was dined
  (['txHash', 'signedTrx_hex'], null, ['txHash', 'signedTrx_hex'])
];

Sign delegate

await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: defaultSnapOrigin,
    request: {
      method: 'near_signDelegate',
      params: {
        network: 'mainnet',
        payer: 'HERE Wallet', // optional
        delegateAction: {
          maxBlockHeight: string;
          actions: Action[];
          publicKey: string;
          nonce: string;
          receiverId: string;
          senderId: string;
        }
      }
    }
  }
})

// Return
{
  transaction: 'base64_signedMessage',
  signature: 'base58_signature',
}
npm i @near-snap/[email protected]

Metadata

Downloads

Maintainers