Eoslime
Search…
Contract

Properties

  • abi
    For convenience you have access to the contract ABI in JSON format
  • name
    For convenience you have access to the contract name
  • provider
    For convenience you have access to the network provider
  • executor
    The account which will execute contract methods (transactions) on the blockchain

Functions

Blockchain Contract Actions

1
let contract = eoslime.Contract.at(ABI_PATH, CONTRACT_NAME, EXECUTOR_1);
2
3
// EXECUTOR_1 will execute `doSmth` transaction on the blockchain
4
await contract.actions.doSmth('Something');
Copied!
eoslime is based on eosjs and when you are calling a contract action, options { broadcast: true, sign: true } are always set to true

Options

Each blockchain contract action has the following options which could be provided as an object after the function arguments
  • from
    If you want to call a contract method from another account(executor) you can do
1
// Local network initialization
2
const eoslime = require('eoslime').init();
3
4
const CONTRACT_NAME = 'mycontract';
5
const ABI_PATH = './contract/contract.abi';
6
7
// Pre-created local network accounts
8
const EXECUTOR_1 = eoslime.Account.load('myacc1', 'privateKey1');
9
const EXECUTOR_2 = eoslime.Account.load('myacc2', 'privateKey2');
10
11
let contract = eoslime.Contract.at(ABI_PATH, CONTRACT_NAME, EXECUTOR_1);
12
13
// EXECUTOR_1 will execute `doSmth` transaction on the blockchain
14
await contract.actions.doSmth('Something');
15
16
// EXECUTOR_2 will execute `doSmth` transaction on the blockchain
17
await contract.actions.doSmth('Something', { from: EXECUTOR_2 });
18
19
// EXECUTOR_1 will execute `doSmth` transaction on the blockchain
20
await contract.actions.doSmth('Something');
Copied!
  • unique
    Nonce action support. Solve the duplicate transaction error
1
// Local network initialization
2
const eoslime = require('eoslime').init();
3
4
const CONTRACT_NAME = 'mycontract';
5
const ABI_PATH = './contract/contract.abi';
6
7
// Pre-created local network accounts
8
const EXECUTOR_1 = eoslime.Account.load('myacc1', 'privateKey1');
9
10
let contract = eoslime.Contract.at(ABI_PATH, CONTRACT_NAME, EXECUTOR_1);
11
12
await contract.actions.doSmth('Something');
13
// Execute `doSmth` one more time with same parameters
14
await contract.actions.doSmth('Something', { unique: true });
Copied!
  • token
    There are cases, where you need to execute a contract function and pay some tokens, but this could be done by processing two transactions. The first one is to your contract, the second one is to eosio.token contract. But what about if the tokens transfer reverts and the transaction to your contract is successful. That is what payable contract actions are purposed for. You should be able to execute an atomic transaction constructed by both actions above.
1
// Local network initialization
2
const eoslime = require('eoslime').init();
3
4
const CONTRACT_NAME = 'mycontract';
5
const ABI_PATH = './contract/contract.abi';
6
7
// Pre-created local network accounts
8
const user1 = eoslime.Account.load('myacc1', 'privateKey1');
9
10
let contract = eoslime.Contract.at(ABI_PATH, CONTRACT_NAME, user1);
11
12
// Execute `doSmth` and transfer 5.0000 SYS tokens to the contract at once(atomically)
13
await contract.actions.doSmth('Your args here', { from: user1, tokens: '5.0000 SYS' });
Copied!

makeInline

Add 'eosio.code' permission to the current account authority. It let the contract to make inline actions/calls to other contracts methods.
Will add eosio.code to the custom authority, if you have loaded your account with it.
1
let contract = eoslime.Contract.at(ABI_PATH, CONTRACT_NAME, CONTRACT_ACCOUNT);
2
3
// CONTRACT_ACCOUNT will obtains 'eosio.code' permission
4
await contract.makeInline();
Copied!

getRawWASM()

Returns contract raw WASM. You could use it to deploy a new contract
1
const contract = eoslime.Contract.at(abi, CONTRACT_NAME);
2
3
const rawWASM = await contract.getRawWASM();
4
const newContract = await eoslime.Contract.deployRaw(rawWASM, abi);
Copied!

Table getters

1
const faucetContract = eoslime.Contract.fromFile(FAUCET_ABI_PATH, faucetAccount.name, faucetAccount);
2
const withdrawers = faucetContract.tables.withdrawers;
Copied!
In order to search in a contract table in an easy way - query chain style exists (Check Providers section). You can access a table by it's name from the ABI.
1
const faucetContract = eoslime.Contract.fromFile(FAUCET_ABI_PATH, faucetAccount.name, faucetAccount);
2
await faucetContract.produce(tokensHolder.name, "100.0000 TKNS", tokenContract.name, "memo");
3
const withdrawers = faucetContract.tables.withdrawers;
4
5
// With equal criteria
6
const equalResult = await withdrawers.equal(tokensHolder.name).find();
7
8
9
// With range criteria
10
const rangeResult = await withdrawers.range(0, 100 * TOKEN_PRECISION).index(2).find();
11
12
13
// With limit
14
const allWithdrawers = await withdrawers.limit(10).find();
15
16
17
// With different index (By Balance)
18
const balanceWithdrawers = await withdrawers.equal(100 * TOKEN_PRECISION).index(2).find();
Copied!
withdrawers is a contract table
Last modified 1yr ago