ethereum-smart-contracts
v0.0.3
Published
Provides basic ERC20 tokens and abi for using with web3.js
Downloads
3
Maintainers
Readme
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:
- ERC20
- to be continued...
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:
- load it with node uri
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 parameteroptions
structure.from
,gas
andgasPrice
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)
// to get token's total supply
const totalSupply = await erc20Token.methods.totalSupply().call()
console.log(`#> totalSupply = ${totalSupply}`)
// or if you want to get user's token balance
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