Ethereum Contract Deployer
Deploy contracts and execute transactions on Ethereum with ease
A simple package for deploying contracts and executing transactions to any ethereum chain you want with just a few simple lines of code.
Installation
OS X & Linux:
npm install eth-contract-deployer --save
Windows:
npm install eth-contract-deployer --save
Usage example
Usage
require eth-contract-deployer in your script
const ethDeployer =
configure eth-contract-deployer
const config = nodeAddress: 'http://127.0.0.1:8545' // node address artifactsDir: '/path/to/artifacts/dir' // path to contracts artifacts (abi/bin files) privateKey: '0x000...' // private key ethDeployer
Deploy a contract
deploy() needs 2 arguments,
- contract name - the contract abi filename as it is on the artifacts dir provided
- constructor arguments - an array containing the values needed for the contract constructor
const token = await ethDeployer
Get contract instance
getInstance() needs 2 arguments
- contract name - the contract abi filename as it is on the artifacts dir provided
- contract address - the contract address
const contractInstance = ethDeployer
Execute a transaction
execute() needs just one argument, a transaction object
const tx = tokenmethodsawait ethDeployer
Get account
get account object
const account = ethDeployerconsole // public address
Get web3 instance
get the web3 instance
const web3 = ethDeployer
example of using the module to prepare a deploy script for a bancor smart token:
- deploys the bancor smart token
- deploys a converter contract for the smart token
- deploys a new ERC20 token
- issue smart tokens
- transfer the new ERC20 token to the converter
- transfer smart token owner ship to the converter
- accept smart token ownership by the converter
- run a conversion between both tokens to test if the whole thing worked
const ethDeployer = const PRIVATE_KEY = ""const ARTIFACTS_DIR = ""const NODE_ADDRESS = "" { // config object for eth deployer const config = nodeAddress: NODE_ADDRESS // node address artifactsDir: ARTIFACTS_DIR // path to contracts artifacts privateKey: PRIVATE_KEY // private key // configure eth deployer ethDeployer // get self address const account = ethDeployer // get web3 instance const web3 = ethDeployer // deploy bancor smart token const smartToken = await ethDeployer // deploy ERC20 token const reserveToken = await ethDeployer // deploy bancor converter const contractRegistryAddress = "0x000..." // Bancor registry contract address goes here const fee = 3000 const ratio = 100000 const converterParams = smartToken_address contractRegistryAddress fee reserveToken_address ratio const converter = await ethDeployer // issue new smartToken tokens const tx = smartTokenmethods await ethDeployer // transfer reserve tokens to converter await ethDeployer // transfer smartToken ownership to converter await ethDeployer // accept smartToken ownership by converter await ethDeployer // check tokens balance before conversion console console // perform conversion smartToken -> reserve token const conversionPath = smartToken_address smartToken_address reserveToken_address await ethDeployer // check tokens balance after conversion console console}