Created
July 13, 2018 18:02
-
-
Save adrianmcli/cb75e325e9bacdc3bd1181357faa7eb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require("web3") // import web3 v1.0 constructor | |
// use globally injected web3 to find the currentProvider and wrap with web3 v1.0 | |
const getWeb3 = () => { | |
const myWeb3 = new Web3(web3.currentProvider) | |
return myWeb3 | |
} | |
// assumes passed-in web3 is v1.0 and creates a function to receive contract name | |
const getContractInstance = (web3) => (contractName) => { | |
const artifact = artifacts.require(contractName) // globally injected artifacts helper | |
const deployedAddress = artifact.networks[artifact.network_id].address | |
const instance = new web3.eth.Contract(artifact.abi, deployedAddress) | |
return instance | |
} | |
module.exports = { getWeb3, getContractInstance } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment