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
let contract =eoslime.Contract.at(ABI_PATH,CONTRACT_NAME,EXECUTOR_1);// EXECUTOR_1 will execute `doSmth` transaction on the blockchainawaitcontract.actions.doSmth('Something');
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
// Local network initializationconsteoslime=require('eoslime').init();constCONTRACT_NAME='mycontract';constABI_PATH='./contract/contract.abi';// Pre-created local network accountsconstEXECUTOR_1=eoslime.Account.load('myacc1','privateKey1');constEXECUTOR_2=eoslime.Account.load('myacc2','privateKey2');let contract =eoslime.Contract.at(ABI_PATH,CONTRACT_NAME,EXECUTOR_1);// EXECUTOR_1 will execute `doSmth` transaction on the blockchainawaitcontract.actions.doSmth('Something'); // EXECUTOR_2 will execute `doSmth` transaction on the blockchainawaitcontract.actions.doSmth('Something', { from:EXECUTOR_2 });// EXECUTOR_1 will execute `doSmth` transaction on the blockchainawaitcontract.actions.doSmth('Something');
unique
Nonce action support. Solve the duplicate transaction error
// Local network initializationconsteoslime=require('eoslime').init();constCONTRACT_NAME='mycontract';constABI_PATH='./contract/contract.abi';// Pre-created local network accountsconstEXECUTOR_1=eoslime.Account.load('myacc1','privateKey1');let contract =eoslime.Contract.at(ABI_PATH,CONTRACT_NAME,EXECUTOR_1);awaitcontract.actions.doSmth('Something'); // Execute `doSmth` one more time with same parametersawaitcontract.actions.doSmth('Something', { unique:true });
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.
// Local network initializationconsteoslime=require('eoslime').init();constCONTRACT_NAME='mycontract';constABI_PATH='./contract/contract.abi';// Pre-created local network accountsconstuser1=eoslime.Account.load('myacc1','privateKey1');let contract =eoslime.Contract.at(ABI_PATH,CONTRACT_NAME, user1);// Execute `doSmth` and transfer 5.0000 SYS tokens to the contract at once(atomically)awaitcontract.actions.doSmth('Your args here', { from: user1, tokens:'5.0000 SYS' });
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.
let contract =eoslime.Contract.at(ABI_PATH,CONTRACT_NAME,CONTRACT_ACCOUNT);// CONTRACT_ACCOUNT will obtains 'eosio.code' permissionawaitcontract.makeInline();
getRawWASM()
Returns contract raw WASM. You could use it to deploy a new contract
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.
constfaucetContract=eoslime.Contract.fromFile(FAUCET_ABI_PATH,faucetAccount.name, faucetAccount);awaitfaucetContract.produce(tokensHolder.name,"100.0000 TKNS",tokenContract.name,"memo");constwithdrawers=faucetContract.tables.withdrawers;// With equal criteriaconstequalResult=awaitwithdrawers.equal(tokensHolder.name).find();// With range criteriaconstrangeResult=awaitwithdrawers.range(0,100*TOKEN_PRECISION).index(2).find();// With limitconstallWithdrawers=awaitwithdrawers.limit(10).find();// With different index (By Balance)constbalanceWithdrawers=awaitwithdrawers.equal(100*TOKEN_PRECISION).index(2).find();