Methods
buyRam (bytes, ?payer)
Buy ram for this account
Defaults/Optionals:
payer - current account
const eoslime = require('eoslime').init();
// Existing accounts on local network
let payer = eoslime.Account.load('myAcc1', 'myPrivateKey1');
let account2 = eoslime.Account.load('myAcc2', 'myPrivateKey2');
// Payer will buy ram for account2
await account2.buyRam(1000, payer);
buyBandwidth (cpu, net, ?payer)
Buy cpu and network for this account
Defaults/Optionals:
payer - current account
const eoslime = require('eoslime').init();
// Existing accounts on local network
let payer = eoslime.Account.load('myAcc1', 'myPrivateKey1');
let account2 = eoslime.Account.load('myAcc2', 'myPrivateKey2');
// Payer will buy cpu and network for account2 for 100 EOS
await account2.buyBandwidth('100.0000 EOS', '100.0000 EOS', payer);
send (receiver, amount, symbol)
Send tokens to another account
Defaults/Optionals:
symbol - EOS
const eoslime = require('eoslime').init();
// Existing accounts on local network
let sender = eoslime.Account.load('myAcc1', 'myPrivateKey1');
let receiver = eoslime.Account.load('myAcc2', 'myPrivateKey2');
// The sender will send 100 EOS tokens to receiver
await sender.send(receiver, `100.0000`, 'EOS');
addAuthority (authorityName, ?threshold)
Creates a new authority and add current account public key in it
Defaults/Optionals:
threshold - 1
const eoslime = require('eoslime').init();
// Existing account on local network
const activeAccount = eoslime.Account.load('myAcc1', 'myPrivateKey1', 'active');
// It will create 'custom' authority. Parent authority will be the 'active' one
await activeAccount.addAuthority('custom', 2);
setAuthorityAbilities(authority, abilities)
Once you add a sub authority, it can not process whatever transaction. You should define what actions of which contracts the authority has permissions to execute.
Parameters
authority - The name of the authority the abilities will be applied to
abilities - Array of the following objects
{ action: 'contract action', contract: 'contract name' }
const faucetContract = await eoslime.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH);
const account = await eoslimeTool.Account.createRandom();
await account.addAuthority('random');
await account.setAuthorityAbilities('random', [
{
action: 'produce',
contract: faucetContract.name
}
]);
const accountRandomAuth = eoslime.Account.load(account.name, account.privateKey, 'random');
await faucetContract.produce(account.name, "100.0000 TKNS", account.name, "memo", { from: accountRandomAuth });
increaseThreshold(threshold)
Increase the authority threshold.
It is useful when you have multiple keys or accounts operating from an authority. This method will allow you to prepare a multisignature account.
const THRESHOLD = 2;
const account = await Account.createRandom();
const keysPair = await eoslime.utils.generateKeys();
// Add one more key to authority
await account.addAuthorityKey(keysPair.publicKey);
// Once threshold being increased,
// both keys should sign the transaction in order to be broadcasted
await account.increaseThreshold(THRESHOLD);
addPermission (permission, ?weight)
Add permission to authority such as eosio.code
Defaults/Optionals:
weight - 1
Adding eosio.code
permission would result in

const eoslime = require('eoslime').init();
// Existing accounts on local network
let account = eoslime.Account.load('myaccount', 'myPrivateKey', 'active');
let tokenFactoryAccount = eoslime.Account.load('tokenfactory', 'factoryPrivateKey', 'active');
/*
It will allow a contract account with eosio.code permission to act on behalf when you are authorizing an action with active authority
Use case:
We have two contracts: TokenFactory and Token
TokenFactory.create behind the scene calls Token.issue_tokens. issue_tokens caller will be the TokenFactory.
However you could want your account to be forwarded to issue_tokens instead of TokenFactory's one
*/
await account.addPermission('eosio.code');
addOnBehalfAccount(accountName, authority, ?weight)
Allow another account to act from your authority

const accounts = await Account.createRandoms(2);
const child = accounts[0];
const parent = accounts[1];
await child.addOnBehalfAccount(parent.name, AUTHORITY);
addOnBehalfKey(publicKey, ?weight)
Add more keys to your authority

const WEIGHT = 2;
const account = await Account.createRandom();
const keysPair = await eoslime.utils.generateKeys();
await account.addOnBehalfKey(keysPair.publicKey, WEIGHT);
setWeight(weight)
Set weight on account public key. This applies to current account authority.
If you have loaded your account with active
authority and public key pub_key
this will result in

const WEIGHT = 2;
const account = await Account.createRandom();
await account.setWeight(WEIGHT);
getAuthorityInfo()
Returns information for loaded authority
const account = await Account.createRandom();
const authority = await account.getAuthorityInfo();
/*
authority =
{
perm_name: 'active',
parent: 'owner',
required_auth:
{
threshold: 1,
keys: [ [Object] ],
accounts: [],
waits: []
}
}
*/
getBalance (?symbol, ?code)
Returns the account balance
Defaults/Optionals:
symbol - EOS
code - eosio.token
const eoslime = require('eoslime').init();
// Existing account on local network
let account = eoslime.Account.load('myAcc1', 'myPrivateKey1');
// custom.token is a contract account with a token deployed on it
await account.getBalance('CUSTOM', custom.token);
Last updated
Was this helpful?