This library for convenient work with Echo-contracts. Can be used to call contracts, sign and broadcast contracts' deployment and execution transactions.
Launched echo node (https://github.com/echoprotocol/echo-core) with open port
import { Echo, Contract, PrivateKey } from "echojs-lib";
const echo = new Echo();
await echo.connect('ws://127.0.0.1:6311');
const bytecode = '6080';
const privateKey = PrivateKey.fromWif('5K2YUVmWfxbmvsNxCsfvArXdGXm7d5DC9pn4yD75k2UaSYgkXTh');
const contractId = await Contract.deploy(bytecode, privateKey, { echo });
// or pass abi in options to get contract instance instead of new contract id
const contract = await Contract.deploy(bytecode, privateKey, { abi: require("abi.json"), echo });
const contract = new Contract(abi, { echo, contractId: '1.14.123' });
const result = await contract.methods.methodName(arg).call();
const broadcastingResult = await contract.methods.methodName(arg).broadcast({ privateKey });
const result = broadcastingResult.decodedResult;
// you can find more information about transaction in this fields:
const { transactionResult, contractResult, events } = broadcastingResult;
import { encode, BigNumber } from "echojs-contract";
encode({ value: false, type: 'bool' });
encode({ value: [1, '2', new BigNumber(3)], type: 'uint8[]' });
decode({
value: '00000000000000000000000000000000fffffffffffffffffffb9d2ac2e07341',
type: 'int128',
});
// returns new BigNumber(-1234567899876543)