near-transaction-mangager
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

NEAR TransactionManager

This library is a utility for creating, signing, and sending transactions. Currently it is a wrapper around near-api-js.

See the docs: https://near-transaction-manager.netlify.app/

Getting Started

  1. install the library from npm: npm i near-transaction-manager
  2. create a TransactionManager instance:
// create a TransactionManager from a NEAR WalletConnection
const transactionManager = TransactionManager.fromWallet(wallet);

or

const keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);

const transactionManager = new TransactionManager({
  transactionCreator: new KeyStoreTransactionCreator({
    keyStore,
    signerId: wallet.getAccountId(),
    networkId: "testnet",
    nodeUrl: "https://rpc.testnet.near.org",
  }),
  transactionSigner: new KeyStoreTransactionSigner({
    keyStore,
    signerId: wallet.getAccountId(),
    networkId: "testnet",
  }),
  transactionSender: new ProviderTransactionSender({
    provider: new JsonRpcProvider("https://rpc.testnet.near.org"),
  }),
});
  1. use the createTransaction, createSignedTransaction, signAndSendTransaction, and signAndSendTransactions methods:
// create a transaction
const transaction = await transactionManager.createTransaction({
  receiverId: "example.testnet",
  actions: [functionCall("method", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
});

// create a signed transaction
const signedTransaction = await transactionManager.createSignedTransaction({
  receiverId: "example.testnet",
  actions: [functionCall("method", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
});

// create, sign, and send a transaction
const outcome = await transactionManager.signAndSendTransaction({
  receiverId: "example.testnet",
  actions: [functionCall("method", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
});

// create, sign, and send many transactions
const outcomes = await transactionManager.signAndSendTransactions([
  {
    receiverId: "example.testnet",
    actions: [functionCall("method1", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
  },
  {
    receiverId: "example.testnet",
    actions: [functionCall("method2", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
  },
  {
    receiverId: "example.testnet",
    actions: [functionCall("method3", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
  },
  {
    receiverId: "example.testnet",
    actions: [functionCall("method4", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
  },
]);

Readme

Keywords

none

Package Sidebar

Install

npm i near-transaction-mangager

Weekly Downloads

1

Version

0.0.1

License

ISC

Unpacked Size

96.3 kB

Total Files

38

Last publish

Collaborators

  • mehtaphysical