ethereum-smart-contracts

0.0.3 • Public • Published

npm version dependencies Status devDependencies Status

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 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)
// 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

Package Sidebar

Install

npm i ethereum-smart-contracts

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

525 kB

Total Files

12

Last publish

Collaborators

  • alesanro