I tried to create a project on Avalanche Blockchain. For the project, I created a local subnet using Subnet-EVM on my Local Avalanche Network. After deploying the subnet, I used the resulting RPC URL in my truffle-config.js file to deploy my smart contract to the local Avalanche Network.
After deploying the smart contract, I tried to trigger the smart contract from a Supabase Edge Function for which I tried to use Web3 library. I tried importing Web3 library using 'https://deno.land/x/web3/mod.ts' but I kept getting an InvalidWorkerResponse error and I was unable to create the instance of Web3. But I tried an alternative to import Web3 from ‘https://cdn.skypack.dev/web3’ which helped me import and create the instance of Web3 and I could create an instance of my Smart Contract as:
const contract = new web3.eth.Contract
(
contractJson.default.abi,
contract_address,
{
from: sender_wallet_address,gasPrice: 0,
}
);
But when I try to call a method from my smart contract using:
const res = await contract.methods.
getTokenBalance(sender_wallet_address).call();
I keep getting "error": "Network request failed”.
I tried to see if my Web3 instance was getting connected using
web3.eth.net.isListening().then(() => console.log("IS Connected \n")).catch((*e*) => console.log("NOT Connected \n", *e*));
and I see that it is not getting connected as it can be seen in the attached screenshot of my console:
My overall finding was that the abi used in the creation of the contract instance is storing all the methods of the smart contract in the contract instance but the result of the web3 not being connected is the reason I am not able to call the methods of my smart contract.
Any help in resolving the problem with Web3 not being connected is highly appreciated.