Account
You can interact with, create or delete NEAR accounts.
Load Account​
This will return an Account object for you to interact with.
const account = await nearConnection.account("example-account.testnet");
Create Account​
Create a sub-account.
// creates a sub-account using funds from the account used to create it.
const account = await nearConnection.account("example-account.testnet");
await account.createAccount(
"sub.example-account.testnet", // sub-account name
"8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc", // public key for sub account
"10000000000000000000" // initial balance for new account in yoctoNEAR
);
For creating .near or .testnet accounts please refer to the cookbook.
Delete Account​
// deletes account found in the `account` object
// transfers remaining account balance to the accountId passed as an argument
const account = await nearConnection.account("example-account.testnet");
await account.deleteAccount("beneficiary-account.testnet");
Get Account Balance​
// gets account balance
const account = await nearConnection.account("example-account.testnet");
await account.getAccountBalance();
Method Account.getAccountBalance
Get Account details​
Returns information about an account, such as authorized apps.
// gets account details in terms of authorized apps and transactions
const account = await nearConnection.account("example-account.testnet");
await account.getAccountDetails();
Method Account.getAccountDetails
Deploy a Contract​
You can deploy a contract from a compiled WASM file. This returns an object with transaction and receipts outcomes and status.
const account = await nearConnection.account("example-account.testnet");
const transactionOutcome = await account.deployContract(
fs.readFileSync("example-file.wasm")
);
Method Account.deployContract
  Â
Interface FinalExecutionOutcome
Send Tokens​
Transfer NEAR tokens between accounts. This returns an object with transaction and receipts outcomes and status.
const account = await nearConnection.account("sender-account.testnet");
await account.sendMoney(
"receiver-account.testnet", // receiver account
"1000000000000000000000000" // amount in yoctoNEAR
);
Method Account.sendMoney
  Â
Interface FinalExecutionOutcome
State​
Get basic account information, such as amount of tokens the account has or the amount of storage it uses.
const account = await nearConnection.account("example-account.testnet");
const accountState = await account.state();
Method Account.state
  Â
Interface AccountView
Access Keys​
You can get and manage keys for an account.
Add Full Access Key​
// takes public key as string for argument
const account = await nearConnection.account("example-account.testnet");
await account.addKey("8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc");
Add Function Access Key​
const account = await nearConnection.account("example-account.testnet");
await account.addKey(
"8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc", // public key for new account
"example-account.testnet", // contract this key is allowed to call (optional)
"example_method", // methods this key is allowed to call (optional)
"2500000000000" // allowance key can use to call methods (optional)
);
Get All Access Keys​
const account = await nearConnection.account("example-account.testnet");
await account.getAccessKeys();
Method Account.getAccessKeys
  Â
Interface AccessKeyInfoView
Delete Access Key​
const account = await nearConnection.account("example-account.testnet");
await account.deleteKey("8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc");