myvetools
v1.4.1
Published
Tools for interacting with VeChainThor
Downloads
83
Readme
MyVeTools
Tools for operating VeChain Thor.
Installation
npm i myvetools
Management of Solidity Compiler
To download a particular Solidity compiler version
node_modules/.bin/solcver -d <VERSION>
To use a downloaded compiler version
node_modules/.bin/solcver -u <VERSION>
Usage
CMD Tools
To create a template TS file for testing smart contracts
node_modules/.bin/mvt -c <FileName>
Package builtin
This package defines the deployed addresses and ABIs of the built-in smart contracts.
To get ABI of function energy
from contract Prototype
:
const abi = getBuiltinABI('prototype', 'energy', 'function')
You can import soloAccounts
to get the 10 default accounts in the solo
mode of the thor client >=1.5.0
.
Package utils
To get ABI:
const abi = JSON.parse(
compileContract(solFilePath, contractName, 'abi')
)
To get bytecode:
const bytecode = compileContract(solFilePath, contractName, 'bytecode')
To get a function ABI:
const abiFunc = getABI(abiContract, funcName, 'function')
Check test/utils.test.ts
for more examples.
Package connexUtils
This package defines functions that interact directly with a Thor network. It includes functions:
deployContract
- to deploy a smart contractcontractCallWithTx
- to call a contract function that changes the contract storagecontractCall
- to call a contract function that does not change the contract storagegetReceipt
- to get the receipt of a transactiondecodeEvent
- to decode a logged event
See test/connexUitls.test.ts
for examples.
Package contract
This package is designed to make it easier to operate a contract.
To create a Contract instance:
const c = new Contract({abi: contractABI})
To deploy the contract:
// Set bytecode
c.bytecode(bin)
// Assume that the constructor is of no inputs and doesn't need transfer any value. Method deploy generates the clause for deploying the contract.
const clause = c.deploy(0)
// Construct and send the transaction. Here `connex` is an instance that implements the Connex interface.
const output = await connex.vendor.sign('tx', [clause]).request()
To send a transaction to call function set(uint256)
:
// Set deployed contract address
c.at(deployedContractAddress)
// Method send generates the clause that calls the function
const clause = c.send('set', 0, newValue)
// Construct and send the transaction.
const output = await connex.vendor.sign('tx', [clause]).request()
To call function get
:
c.connex(connex)
const output = await c.call('get')
See test/contract.test.ts
for more examples.
Test
To test package connexUtils
, you will have to run the Thor client in the solo mode.