eth-new-contract
eth-new-contract
is an npm module that allows you to deploy a Solidity contract and create a web3 contract instance straight from source. Subsequent calls use cached bytecode for performance.
The default new
method of web3 has the somewhat quirky behavior of invoking its callback twice—once to return the transaction hash and once when the contract is deployed. Usually you don't care about the transaction hash initially, so in this library, the promise resolves when it is deployed. contract.transactionHash
can then be accessed like on any web3 contract.
Install
$ npm install --save eth-new-contract
Usage
const Web3 = const provider = 'http://localhost:8545'const web3 = providerconst newContract = // instantiate from sourceconst source = 'contract MyContract { function GetAnswer() constant returns(uint) { return 42; } }'
You can also compile and generate the web3 constructor yourself and pass it to eth-new-contract
:
const solc = const Web3 = const web3 = 'http://localhost:8545'const newContract = // no provider needed // compile contractconst compilation = solcconst bytecode = compilationcontractscontractNamebytecodeconst abi = JSONconst MyContract = web3eth // deploy
Developer Notes
bip39
incompatibility with testrpc requires explicit dependency version: https://github.com/ethereumjs/testrpc/issues/313#issuecomment-304790839
License
ISC © Raine Revere