eth_contracts_halper
v0.4.2
Published
utility for compiling and creating ethereum smart contracts
Downloads
29
Maintainers
Readme
eth_contracts_halper
Utility for compiling and creating ethereum smart contracts
Installation
Use the package manager npm to install eth_contracts_halper.
npm install eth_contracts_halper
Usage
Simple usage
var contract = new Contract({ filePath: __dirname + '/contranct.sol', contractName: 'CONTRACT' }); console.log(contract.copiledWithVersion);
Use alternative compiler version
You can use a localy installed alternative compiler version, if it is available.
List of installed version:- 0.8.20
- 0.7.6
- 0.4.26
You can also check the package.json file for more information about available compiler versions.
Alternative compiler version must be described like"solc_0.8.20": "npm:[email protected]"
independencies
section.For usage of alternative compiler version
INSTALLED LOCALY
you need to declare compiler version likecompilerVersion: '0.8.20'
(without commit hash)var contract = new Contract({ filePath: __dirname + '/contranct.sol', contractName: 'CONTRACT', compilerVersion: '0.8.20' });
Use remote compiler version
You can use a compiler version that is not installed locally.
Compiler version must be declared with commit hash, like in example below.
It will be downloaded but constuctor will not return the contrarct ready to use.
You neeed to declare 'remote' as compilerVersion, and end pass the verion in function remoteCompile() as argument. Using a remote compiler version requires asyncronous code and can't be used in constructor, for this reason you need to use a remoteCompile() function, that will return a promise.var contract = new Contract({ filePath: __dirname + '/contranct.sol', contractName: 'CONTRACT', compilerVersion: 'remote' }); let contract = await contract.remoteCompile('v0.4.26+commit.4563c3fc')
Call contract methods
You can call contract methods using the methods object. Don't forget to set web3 provider during contract initialization.
var contract = new Contract({ filePath: __dirname + '/contranct.sol', contractName: 'CONTRACT' web3Provider: 'http://localhost:8545' }); let result = await contract.methods.methodName().call();
Debugging
For debugging mode you need to set DEBUG environment variable
example:
DEBUG=true node index.js
Tests
npm test