0

I am writing this question because of today I have been struggling with something on my dApp run locally and with the use of anvil as blockchain with a basic configuration:

anvil --host 0.0.0.0 --no-cors -b 10 

I am using foundry on a docker container as part of a compose, where the network bridge it with FE and I am interaction with it with Viem library version: ^2.7.15.

All is initiated normally (note that the process I did initially was with a test account that I previously had which was funded transferring ETH from one of the anvil default accounts to that one) I create a walletClient with anvil as chain:

createWalletClient({ account, chain: anvil, transport: http(<ANVIL_RPC_URL>), }) 

and then I create the contract instance with it:

getContract({ address: contractAddress, abi: contractAbi, client, }) 

But when using it to call the contract:

await contract.write.<METHOD_NAME>(); 

I was getting the following error:

Method use response

Initially I believed that it was the way I was using the contract instance (as I normally work with ethers & web3 libraries) however when inspecting network data I saw that this was blockchain response to eth_sendTransaction:

{ "jsonrpc": "2.0", "id": 12, "error": { "code": -32602, "message": "No Signer available" } } 

To the sent data:

{ "jsonrpc": "2.0", "id": 5, "method": "eth_sendTransaction", "params": [ { "data": "0x4e71d92d", "from": "0x45623F240f9e3d1bb307FCBEBA44ed77b4E3211a", "to": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" } ] } 

For what I did the same flow importing to Metamask one of the 10 default anvil accounts and it worked:

Success Request:

{ "jsonrpc": "2.0", "id": 5, "method": "eth_sendTransaction", "params": [ { "data": "0x4e71d92d", "from": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "to": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" } ] } 

Success Result:

{ "jsonrpc": "2.0", "id": 5, "result": "0x660137731c513effe049d00db0bfee12eaadbf09f976e0395223c8788fcea1e9" } 

Then I tested sending back the funded ETH from my test account from one of the anvil default accounts with:

cast send <ANVIL_DEFUALT_ACC> --value <ETH> --private-key <MY_TEST_ACC_PK> 

And it went through (as well as running the same contract request), I would like to know why from the FE I can not make use of non anvil default EOA to send request to a contract and I can indeed from an anvil default account.

I have the following questions:

  1. Why does this happens?
  2. Do I miss any anvil configuration?

I would appreciate so much any answer to this. Thank you!

1 Answer 1

0

It looks like you haven’t added Anvil network to your MetaMask.

If you follow the steps from 1 to 6 of this answer.

Then, after the default Anvil account is imported to your MetaMask, you can just transfer the native tokens (ie., GO in the given answer) to any of your existing MetaMask account.

And then, you can execute any smart contract function, given that the contract is also deployed on the Anvil network running with the exact same configuration (as used in the MetaMask while adding Anvil network).

3
  • Hello! Thank you for the answer. However the lack of native token is not the cause, as I am initiating Anvil in docker compose I did an entrypoint where I initiate Anvil and do some actions after that and the first thing that I do is to send funds to the addresses specified in another file from the last account from the 10 given when initiating Anvil. After doing this and trying to execute transaction in blockchain to one of the addresses funded, it reverts, however when using one of the 10 EOA given by anvil imported on Metamask it does not revert. I have not been able to find the cause Commented Jul 17, 2024 at 14:42
  • Have you added the Anvil network to your MetaMask? Commented Jul 17, 2024 at 14:46
  • Yes, I have it there. But is not the problem either. While using Foundry's wallets I can be on Ethereum while doing the action and it fulfills as the provider is not being taken from MM Commented Jul 23, 2024 at 9:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.