@near-snap/plugin

0.7.0 • Public • Published

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',
}

Readme

Keywords

none

Package Sidebar

Install

npm i @near-snap/plugin

Weekly Downloads

1,658

Version

0.7.0

License

(MIT-0 OR Apache-2.0)

Unpacked Size

339 kB

Total Files

6

Last publish

Collaborators

  • near-snap