Utility for compiling and creating ethereum smart contracts
Use the package manager npm to install eth_contracts_halper.
npm install eth_contracts_halper
-
var contract = new Contract({ filePath: __dirname + '/contranct.sol', contractName: 'CONTRACT' }); console.log(contract.copiledWithVersion);
-
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:solc@0.8.20"
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' });
-
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')
-
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();
For debugging mode you need to set DEBUG environment variable
example:
DEBUG=true node index.js
npm test