Created
April 14, 2022 23:08
-
-
Save MCarlomagno/d86014fb550ef41a17ef553f750c94a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Web3 from "web3"; | |
// we import the abi file created after | |
// the migration using truffle. | |
import Persssist from '../../public/abis/Persssist.json'; | |
async initializeContractLocal() { | |
if (window.ethereum) this.web3 = new Web3(window.ethereum) | |
else if (window.web3) this.web3 = new Web3(window.web3.currentProvider); | |
if(!this.web3) throw 'Web3 not initialized'; | |
const networkId = await this.web3.eth.net.getId(); | |
const networkData = (PersssistLocal as any).networks[networkId]; | |
if (networkData) { | |
this.contract = new this.web3.eth.Contract( | |
(Persssist as any).abi, | |
networkData.address | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment