0

I am forking Ethereum blockchain using Alchemy's api. Below is my chain config

 module.exports = {
  solidity: 
  {
    compilers :[
    {version : "0.8.17"},
    {version: "0.8.4"},{
      version : "0.8.20"
    }]},
    networks :{
      hardhat : {
        forking : {
          enabled : true,
          url : "https://eth-mainnet.g.alchemy.com/v2/ApiKey",
          chainId :31337
        }
      }
    }
};

And after calling curl with the following

 curl --location --request POST 'localhost:8545/' --header 'Content-Type: application/json' --data-raw '{
 "jsonrpc": "2.0",
  "method": "eth_blockNumber",
  "params": [],
  "id": 83
}'

I get this response

{"jsonrpc":"2.0","id":83,"result":"0x119f1f1"}

whenever I try to call the existing smart contract functions I am getting the error

error: ContractExecutionError: Error happened while trying to execute a function inside a smart contract
innerError: [Eip838ExecutionError: Error: Transaction reverted without a reason string] 

Below is my script

const {Web3} = require('web3');
const web3 = new Web3("http://127.0.0.1:8545");
const oracleAbi = require("../oracle.json");
const oracle = "0x54586bE62E3c3580375aE3723C145253060Ca0C2";
const oracleContract = new web3.eth.Contract(oracleAbi, oracle);
async function setOracleAddress() {
    try {
        const accounts = await web3.eth.accounts.wallet.add("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
        const fromAccount = accounts[0].address
      
        const getAddress = await oracleContract.methods.getSourceOfAsset("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").call();
        console.log({getAddress});
    } catch (error) {
        console.log({error});
    }
}
setOracleAddress()

neither read nor write functions are being called. In this case, It is throwing error while calling the getSourceOfAsset function

3
  • Are you sure that your contract is actually deployed on your local network? Nov 1 at 15:25
  • I didn't deploy any contract. I want to use already deployed contract in mainnet Nov 2 at 14:20
  • The contract will not exist on your hardhat network unless you deploy it there(and if you deploy it, the address will be different than the one on mainnet). Nov 7 at 18:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.