Deployment

deploy

Use this method in case you don't have a contract account. It creates a new contract account on which the contract is being deployed. The creator of the new contract account is the provider's default account.

Useful Scenario

We have two tests and one contract account. The first test writes to the contract storage, but you need this storage to be clear for the second test due to some assertions or something like that depending on the use-case.

deploy(wasmPath, abiPath, ?options)

Deploy a contract by providing the directory paths to your WASM and ABI files

// Local network initialization
const eoslime = require('eoslime').init();

const WASM_PATH = './contract/contract.wasm';
const ABI_PATH = './contract/contract.abi';

const contract = await eoslime.Contract.deploy(WASM_PATH, ABI_PATH);

deployRaw(rawWASM, abiJSON, ?options)

Deploy a contract from WASM string and ABI in JSON format A typical use case for deployRaw is in CI/CD. You don’t want to compile your contract every time, however your tests needs WASM and ABI. A good approach is to deploy your contract on a test network like Jungle one and retrieve its WASM and ABI for your tests

const eoslime = eoslime.init('jungle');
const deployedContract = 'your_contract_name'; 

const contractA_ABI = await eoslime.Provider.getABI(deployedContract);
const contractA_WASM = await eoslime.Provider.getRawWASM(deployedContract);
    
const contractB = await eoslime.Contract.deployRaw(contractA_WASM, contractA_ABI); 

deployOnAccount

Use this method in case you already have an account on which you want to deploy a new contract or when you have an account with already deployed contract and you want to upgrade it.

deployOnAccount(wasmPath, abiPath, contractAccount, ?options)

Deploy a contract by providing the directory paths to your WASM and ABI files, and an account used to deploy the code on

const eoslime = require('eoslime').init();

const WASM_PATH = './contract/contract.wasm';
const ABI_PATH = './contract/contract.abi';

const contractAccount = eoslime.Account.load('name', 'privateKey');

const contract = await eoslime.Contract.deployOnAccount(WASM_PATH, ABI_PATH, contractAccount);

deployRawOnAccount(rawWASM, abiJSON, contractAccount, ?options)

Deploy a contract by providing WASM string, ABI in JSON format and an account used to deploy the code on

const eoslime = eoslime.init('jungle');
const deployedContract = 'your_contract_name'; 

const contractAccount = eoslime.Account.load('name', 'privateKey');    
const contractA_ABI = await eoslime.Provider.getABI(deployedContract);
const contractA_WASM = await eoslime.Provider.getRawWASM(deployedContract);
    
const contractB = await eoslime.Contract.deployRawOnAccount(contractA_WASM, contractA_ABI, contractAccount); 

Options

inline

If true, contract account's active authority obtains 'eosio.code' permission. In this way the contract has the ability to do inline actions (calls another contract)

const eoslime = require('eoslime').init();

const WASM_PATH = './contract/contract.wasm';
const ABI_PATH = './contract/contract.abi';

// contract account's active authority obtains `eosio.code` permission
const contract = await eoslime.Contract.deploy(WASM_PATH, ABI_PATH, { inline: true });
// OR
const contractAccount = eoslime.Account.load('name', 'privateKey');
const contract = await eoslime.Contract.deployOnAccount(WASM_PATH, ABI_PATH, { inline: true });

Events

deploy

You can process some logic every time a new contract is deployed.

eoslime.Contract.on('deploy', (contract, txReceipts) => 
        {
                /*
                 txReceipts is an array with two transactions inside
                        1. set code transaction
                        1. set abi transaction
                */
                
                // do some custom logic
        }
);
    

Last updated