The Account class models Antelope accounts and is the primary entity used to interact with the blockchain. A contract can be deployed on an account and used to send transactions and read table data.
Accounts are created using the createAccount method of the Chain object.
Account name
Reference to the Chain instance this account belongs to
The contract installed on the account if it exists
parameters
- chain - chain: Instance of the Chain class
- name - string: Name of the new antelope account
Note: The recommended method of creating a new account is to call Chain.createAccount()
Updates the permission for an account.
parameters
- permission - string: permission name
- parent - string: parent permission name
- threshold - number: number of weights required
- keys - keys: list of public keys and weights
- accounts: list of accounts and weights
- waits: list of time weights and waits
Example
Add the permission testauth as a child of the active permission. The testauth permission will have a threshold of 2 and two keys each with a weight of 1. The permission [email protected] will have a weight of 2.
await account.updateAuth(
'testauth',
'active',
2,
[
{
key: 'EOS7Gk5QTRcKsK5grAuZkLyPTSw5AcQpCz2VDWGi5DPBvfZAG7H9b',
weight: 1,
},
{
key: 'EOS8cFt6PzBL79kp9vPwWoX8V6cjwgShbfUsyisiZ1M8QaFgZtep6',
weight: 1,
},
],
[
{
permission: {
actor: 'acc11.test',
permission: 'eosio.code',
},
weight: 2,
},
]
);
Result
cleos -u http://localhost:708 get account testaccount1
created: 2022-07-24T19:46:54.000
permissions:
owner 1: 1 EOS5dUsCQCAyHVjnqr6BFqVEE7w8XksnkRtz22wd9eFrSq4NHoKEH
active 1: 1 EOS5dUsCQCAyHVjnqr6BFqVEE7w8XksnkRtz22wd9eFrSq4NHoKEH
testauth 2: 1 EOS7Gk5QTRcKsK5grAuZkLyPTSw5AcQpCz2VDWGi5DPBvfZAG7H9b, 1 EOS8cFt6PzBL79kp9vPwWoX8V6cjwgShbfUsyisiZ1M8QaFgZtep6, 2 [email protected]
A wrapper around the get_account RPC method.
A wrapper around the get_currency_balance RPC method.
Adds a permission to an account. The new permission will inherit the active authorization.
Example
Adds a new persmission addauth1111 as a child to the testauth permission.
await account.addAuth('addauth11111', 'testauth');
Result
cleos -u http://localhost:1384 get account testaccount1
created: 2022-07-24T19:55:15.000
permissions:
owner 1: 1 EOS5dUsCQCAyHVjnqr6BFqVEE7w8XksnkRtz22wd9eFrSq4NHoKEH
active 1: 1 EOS5dUsCQCAyHVjnqr6BFqVEE7w8XksnkRtz22wd9eFrSq4NHoKEH
newcodeauth 1: 1 [email protected]
testauth 2: 1 EOS7Gk5QTRcKsK5grAuZkLyPTSw5AcQpCz2VDWGi5DPBvfZAG7H9b, 1 EOS8cFt6PzBL79kp9vPwWoX8V6cjwgShbfUsyisiZ1M8QaFgZtep6, 2 [email protected]
addauth11111 1: 1 EOS5dUsCQCAyHVjnqr6BFqVEE7w8XksnkRtz22wd9eFrSq4NHoKEH
A wrapper around the eosio:linkauth contract action.
Example
Allow addauth11111 to authorize the eosio.token:transfer action.
const transaction = await account.linkAuth('eosio.token', 'transfer', 'addauth11111');
Result
The addauth1111 autority is able to authorize the eosio.token:transfer action.
addCode(permission: string)
A helper function to set the eosio.code permission on a given account.
A wrapper around eosio:token action. Assumes the chain has been started with system contracts installed.
A wrapper around the eosio:setcode and eosio:setabi actions.
Example
await contractAccount.setContract({
abi: './contracts/build/testcontract.abi',
wasm: './contracts/build/testcontract.wasm'
});