Nhảy đến nội dung chính

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");

Class Account

Tạo 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
);

Method Account.createAccount

For creating .near or .testnet accounts please refer to the cookbook.

Xóa 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");

Method Account.deleteAccount

Kiểm tra số dư tài khoản

// gets account balance
const account = await nearConnection.account("example-account.testnet");
await account.getAccountBalance();

Method Account.getAccountBalance

Xem thông tin chi tiết của account

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 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

Các RPC Endpoint

You can get and manage keys for an account.

Thêm một Full Access Key

// takes public key as string for argument
const account = await nearConnection.account("example-account.testnet");
await account.addKey("8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc");

Method Account.addKey

Thêm một 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)
);

Method Account.addKey

Lấy tất cả các Access Key

const account = await nearConnection.account("example-account.testnet");
await account.getAccessKeys();

Method Account.getAccessKeys     Interface AccessKeyInfoView

Xóa Access Key

const account = await nearConnection.account("example-account.testnet");
await account.deleteKey("8hSHprDq2StXwMtNd43wDTXQYsjXcD4MJTXQYsjXcc");

Method Account.deleteKey

Was this page helpful?