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:
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:
- Why does this happens?
- Do I miss any anvil configuration?
I would appreciate so much any answer to this. Thank you!
