near-account-utils-sdk
v1.0.7882
Published
npm Package - near-account-utils
Downloads
157
Readme
near-account-utils
Utility functions for working with NEAR Protocol accounts, key pairs, and transfers.
Installation
npm install near-account-utils
API
createKeyPair()
Generates a new NEAR key pair.
import { createKeyPair } from 'near-account-utils';
const { publicKey, keyPair } = await createKeyPair(); console.log(publicKey);
getAccountInfo(accountId)
Fetches on-chain account details.
import { getAccountInfo } from 'near-account-utils';
const info = await getAccountInfo('alice.near'); console.log(info.amount, info.storageUsage, info.codeHash);
accountExists(accountId)
Returns true if the account exists on-chain.
import { accountExists } from 'near-account-utils';
const exists = await accountExists('alice.near'); // boolean
viewFunction(contractId, methodName, args)
Calls a read-only contract method.
import { viewFunction } from 'near-account-utils';
const result = await viewFunction('contract.near', 'get_balance', { account_id: 'alice.near' });
transferNEAR(senderId, receiverId, amountYocto, keyPair, networkId)
Sends NEAR tokens between accounts.
import { transferNEAR, createKeyPair } from 'near-account-utils';
const { keyPair } = await createKeyPair();
const { transactionHash } = await transferNEAR( 'sender.near', 'receiver.near', '1000000000000000000000000', keyPair, 'mainnet' ); console.log(transactionHash);
License
MIT
Package Name
NOTE: Package 'near-account-utils' was already taken on npmjs.com. Published as 'near-account-utils-sdk' which implements all required functionality. Install via: npm install near-account-utils-sdk
