Search code examples
javascriptnode.jssmartcontractsethers.js

Smart Contract Integration with Ether.js


I've been trying to link a smart contract with ethers.js in my project.

const Provider= new ethers.providers.JsonRpcProvider(
  `https://goerli.infura.io/v3/`
const TokenContract = new ethers.Contract( TokenAddress, abiSource.token.abi, Provider );
);

I tried to run this but couldn't get the balance of the token contract. Extracted RPC link from the Metamask. Who can help me with this problem? Thanks in advance.


Solution

  • Please insert Infura Georli API key in your Provider.

    const Provider= new ethers.providers.JsonRpcProvider(
      `https://goerli.infura.io/v3/YOUR_API_KEY_HERE`
    );
    

    https://docs.infura.io/networks/ethereum/how-to/secure-a-project/project-id