npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eth-contract-deployer

v0.2.2

Published

deploy ethereum contracts and execute after deployment functions with ease

Downloads

7

Readme

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 = require("eth-contract-deployer")

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.config(config)

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.deploy("ContractName", ["value1", "value2", 'value3'])

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.getInstance("ContractName", "0x000...")

Execute a transaction

execute() needs just one argument, a transaction object

const tx = token.methods.transfer("0x000...", "10000000000000000000000")
await ethDeployer.execute(tx)

Get account

get account object

const account = ethDeployer.getAccount()
console.log(account.address) // public address

Get web3 instance

get the web3 instance

const web3 = ethDeployer.getWeb3Instance()

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 = require("eth-contract-deployer")

const PRIVATE_KEY = ""
const ARTIFACTS_DIR = ""
const NODE_ADDRESS = ""

async function run() {
  // 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.config(config)

  // get self address
  const account = ethDeployer.getAccount()

  // get web3 instance
  const web3 = ethDeployer.getWeb3()

  // deploy bancor smart token
  const smartToken = await ethDeployer.deploy("SmartToken", ["test token", "TST", 18])

  // deploy ERC20 token
  const reserveToken = await ethDeployer.deploy("ERC20Token", ["reserve token", "RSV", 18, "10000000000000000000000"])

  // 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.deploy("BancorConverter", converterParams)

  // issue new smartToken tokens
  const tx = smartToken.methods.issue(account.address, "10000000000000000000000")
  await ethDeployer.execute(tx)

  // transfer reserve tokens to converter
  await ethDeployer.execute(reserveToken.methods.transfer(converter._address, "1000000000000000000000"))

  // transfer smartToken ownership to converter
  await ethDeployer.execute(smartToken.methods.transferOwnership(converter._address))

  // accept smartToken ownership by converter
  await ethDeployer.execute(converter.methods.acceptTokenOwnership())

  // check tokens balance before conversion
  console.log("smartToken balance", web3.utils.fromWei(await smartToken.methods.balanceOf(account.address).call()))
  console.log("reserve balance", web3.utils.fromWei(await reserveToken.methods.balanceOf(account.address).call()))

  // perform conversion smartToken -> reserve token
  const conversionPath = [smartToken._address, smartToken._address, reserveToken._address]
  await ethDeployer.execute(await converter.methods.quickConvert(conversionPath, "1000000000000000000", "1"))

  // check tokens balance after conversion
  console.log("smartToken balance", web3.utils.fromWei(await smartToken.methods.balanceOf(account.address).call()))
  console.log("reserve balance", web3.utils.fromWei(await reserveToken.methods.balanceOf(account.address).call()))
}

run()
  .then((t) => {
    process.exit(0)
  })
  .catch((error) => {
    console.log(error)
    process.exit(1)
  })

Meta

@ozam15[email protected]

https://seedbed.io