Eoslime
Search…
Methods

buyRam (bytes, ?payer)

Buy ram for this account
Defaults/Optionals:
  • payer - current account
1
const eoslime = require('eoslime').init();
2
// Existing accounts on local network
3
let payer = eoslime.Account.load('myAcc1', 'myPrivateKey1');
4
let account2 = eoslime.Account.load('myAcc2', 'myPrivateKey2');
5
6
// Payer will buy ram for account2
7
await account2.buyRam(1000, payer);
Copied!

buyBandwidth (cpu, net, ?payer)

Buy cpu and network for this account
Defaults/Optionals:
  • payer - current account
1
const eoslime = require('eoslime').init();
2
// Existing accounts on local network
3
let payer = eoslime.Account.load('myAcc1', 'myPrivateKey1');
4
let account2 = eoslime.Account.load('myAcc2', 'myPrivateKey2');
5
6
// Payer will buy cpu and network for account2 for 100 EOS
7
await account2.buyBandwidth('100.0000 EOS', '100.0000 EOS', payer);
Copied!

send (receiver, amount, symbol)

Send tokens to another account
Defaults/Optionals:
  • symbol - EOS
1
const eoslime = require('eoslime').init();
2
// Existing accounts on local network
3
let sender = eoslime.Account.load('myAcc1', 'myPrivateKey1');
4
let receiver = eoslime.Account.load('myAcc2', 'myPrivateKey2');
5
6
// The sender will send 100 EOS tokens to receiver
7
await sender.send(receiver, `100.0000`, 'EOS');
Copied!

addAuthority (authorityName, ?threshold)

Creates a new authority and add current account public key in it
Defaults/Optionals:
  • threshold - 1
1
const eoslime = require('eoslime').init();
2
// Existing account on local network
3
const activeAccount = eoslime.Account.load('myAcc1', 'myPrivateKey1', 'active');
4
5
// It will create 'custom' authority. Parent authority will be the 'active' one
6
await activeAccount.addAuthority('custom', 2);
Copied!

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
  1. 1.
    authority - The name of the authority the abilities will be applied to
  2. 2.
    abilities - Array of the following objects
    1
    {
    2
    action: 'contract action',
    3
    contract: 'contract name'
    4
    }
    Copied!
1
const faucetContract = await eoslime.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH);
2
3
const account = await eoslimeTool.Account.createRandom();
4
await account.addAuthority('random');
5
6
await account.setAuthorityAbilities('random', [
7
{
8
action: 'produce',
9
contract: faucetContract.name
10
}
11
]);
12
13
const accountRandomAuth = eoslime.Account.load(account.name, account.privateKey, 'random');
14
await faucetContract.produce(account.name, "100.0000 TKNS", account.name, "memo", { from: accountRandomAuth });
Copied!

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.
1
const THRESHOLD = 2;
2
const account = await Account.createRandom();
3
4
const keysPair = await eoslime.utils.generateKeys();
5
6
// Add one more key to authority
7
await account.addAuthorityKey(keysPair.publicKey);
8
// Once threshold being increased,
9
// both keys should sign the transaction in order to be broadcasted
10
await account.increaseThreshold(THRESHOLD);
Copied!

addPermission (permission, ?weight)

Add permission to authority such as eosio.code
Defaults/Optionals:
  • weight - 1
Adding eosio.code permission would result in
1
const eoslime = require('eoslime').init();
2
// Existing accounts on local network
3
let account = eoslime.Account.load('myaccount', 'myPrivateKey', 'active');
4
let tokenFactoryAccount = eoslime.Account.load('tokenfactory', 'factoryPrivateKey', 'active');
5
6
/*
7
It will allow a contract account with eosio.code permission to act on behalf when you are authorizing an action with active authority
8
Use case:
9
We have two contracts: TokenFactory and Token
10
TokenFactory.create behind the scene calls Token.issue_tokens. issue_tokens caller will be the TokenFactory.
11
However you could want your account to be forwarded to issue_tokens instead of TokenFactory's one
12
13
*/
14
await account.addPermission('eosio.code');
Copied!

addOnBehalfAccount(accountName, authority, ?weight)

Allow another account to act from your authority
1
const accounts = await Account.createRandoms(2);
2
const child = accounts[0];
3
const parent = accounts[1];
4
5
await child.addOnBehalfAccount(parent.name, AUTHORITY);
Copied!

addOnBehalfKey(publicKey, ?weight)

Add more keys to your authority
1
const WEIGHT = 2;
2
const account = await Account.createRandom();
3
4
const keysPair = await eoslime.utils.generateKeys();
5
await account.addOnBehalfKey(keysPair.publicKey, WEIGHT);
Copied!

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
1
const WEIGHT = 2;
2
const account = await Account.createRandom();
3
4
await account.setWeight(WEIGHT);
Copied!

getAuthorityInfo()

Returns information for loaded authority
1
const account = await Account.createRandom();
2
const authority = await account.getAuthorityInfo();
3
4
/*
5
authority =
6
{
7
perm_name: 'active',
8
parent: 'owner',
9
required_auth:
10
{
11
threshold: 1,
12
keys: [ [Object] ],
13
accounts: [],
14
waits: []
15
}
16
}
17
*/
Copied!

getBalance (?symbol, ?code)

Returns the account balance
Defaults/Optionals:
  • symbol - EOS
  • code - eosio.token
1
const eoslime = require('eoslime').init();
2
// Existing account on local network
3
let account = eoslime.Account.load('myAcc1', 'myPrivateKey1');
4
5
// custom.token is a contract account with a token deployed on it
6
await account.getBalance('CUSTOM', custom.token);
Copied!
Last modified 1yr ago