0.1.1 • Published 3 years ago

near-transaction-manager v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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 Account
const transactionManager = TransactionManager.fromAccount(account);

or

// 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.createSignAndSendTransaction({
  receiverId: "example.testnet",
  actions: [functionCall("method", {}, DEFAULT_FUNCTION_CALL_GAS, [])],
});

// create, sign, and send many transactions
const outcomes = await transactionManager.bundleCreateSignAndSendTransactions([
  {
    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, [])],
  },
]);
0.1.1

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago