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