Skip to content

Instantly share code, notes, and snippets.

@MCarlomagno
Created April 14, 2022 23:08
Show Gist options
  • Save MCarlomagno/d86014fb550ef41a17ef553f750c94a4 to your computer and use it in GitHub Desktop.
Save MCarlomagno/d86014fb550ef41a17ef553f750c94a4 to your computer and use it in GitHub Desktop.
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