Common information
This package provides an ability to access and use basic smart contracts without any need to compile them manually.
List of provided smart contract interfaces:
List of provided tokens:
- MassTransfer ERC20 compatible token
Usage
First of all, import a module
const ContractsContext = require("ethereum-smart-contracts")
Then there might be two ways:
const context = ContractsContext.withUri("https://mainnet.infura.io/", options)
- or inject
web3
instance directly
const context = new ContractsContext(web3, options)
options
parameter should have the next layout: see parameter options
structure. from
, gas
and gasPrice
are needed to be provided, data
is optional.
After initial setup contracts are available to use them.
For example, to load any ERC20
-token (let use EOS token address) you need to do
const tokenAddress = "0x7b39940dbac110f1227d37c395675def270afcd7"
const erc20Token = context.getERC20TokenAt(tokenAddress)
const totalSupply = await erc20Token.methods.totalSupply().call()
console.log(`#> totalSupply = ${totalSupply}`)
const userAddress = "0x00000000000000000000000000000000000000b1"
const balanceOf = await erc20Token.methods.balanceOf(userAddress).call()
console.log(`#> user balance (${userAddress}) = ${balanceOf}`)
Examples
Some example of how to use smart contracts you can find in examples directory