DePayFi / web3-mock

🤡 JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.
https://depay.com
MIT License
84 stars 21 forks source link

Receive invalid signer or provider when using JsonRpcProvider in mocks #35

Closed hubert-de-lalye closed 1 day ago

hubert-de-lalye commented 1 month ago

Trying this as instruction: https://github.com/DePayFi/web3-mock?tab=readme-ov-file#providers-1


const provider = new ethers.JsonRpcProvider('https://arb1.arbitrum.io/rpc');

mock({
  blockchain: "arbitrum",
  provider: provider,
  request: {
    to: '0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a',
    api: Token.abi,
    method: "balanceOf",
    params: "0x9f7198eb1b9Ccc0Eb7A07eD228d8FbC12963ea33",
    return: "1000000000000000000",
  },
});

const contract = new ethers.Contract('0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a', Token.abi, provider);

const data = await contract.balanceOf("0x9f7198eb1b9Ccc0Eb7A07eD228d8FbC12963ea33");

Receiving:

invalid signer or provider (argument="signerOrProvider", value={"_blockchain":"arbitrum"}, code=INVALID_ARGUMENT, version=contracts/5.7.0)

When I'm removing mock(...) - everything is fine, ethers make correct call and get correct response.

What am I doing wrong?

hubert-de-lalye commented 1 month ago

Just looked at package.json, and see ethers^5, does this library compatible with ethers >= 6?

0xNe0x1 commented 1 day ago

Hi,

This library is designed to mock wallets, not providers, making it ideal for testing dApps. However, note that it won't mock anything that doesn't interact with window.ethereum or a wallet extension.

Currently, Ethers v6 and above is not supported. But since npm allows for multiple versions of dependencies to coexist, and this library includes a bundled version of Ethers, it shouldn't pose an issue for most use cases.