[fhevmjs] Error to create an instance

Hello.

I’ve compiled my own geth (from go-ethereum v1.13.5) as described at fhEVM-go Integration
(docs.zama.ai/fhevm-go/getting-started/integration).

The node started successfully, the EncryptedERC20 contract was deployed successfully (I’ve used Zama Hardhat template).
Now I want to connect to the network like this:

const networkUrl = "http://127.0.0.1:8545/";
const provider = new ethers.JsonRpcProvider(networkUrl);

async function createFhevmInstance() {
  const network = await provider.getNetwork()
  const chainId = network.chainId.toString()

  const ret = await provider.call({
    // fhe lib address, may need to be changed depending on network
    to: "0x000000000000000000000000000000000000005d", // 93 in geth
    // first four bytes of keccak256('fhePubKey(bytes1)') + 1 byte for library
    data: "0xd9d47bb001",
  })  
  const decoded = ethers.AbiCoder.defaultAbiCoder().decode(["bytes"], ret);
  const publicKey = decoded[0];
  return createInstance({ chainId: chainId, publicKey: publicKey });
}

And I’ve got an error:

Error: missing revert data (action="call", data=null, reason=null, transaction={ "data": "0xd9d47bb001", "to": "0x000000000000000000000000000000000000005d" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.13.2)
    at makeError (file:///home/pyro/dev/projects/vitim/swafe/sw_wallet/node_modules/ethers/lib.esm/utils/errors.js:124:21)
    at getBuiltinCallException (file:///home/pyro/dev/projects/vitim/swafe/sw_wallet/node_modules/ethers/lib.esm/abi/abi-coder.js:102:12)
    at AbiCoder.getBuiltinCallException (file:///home/pyro/dev/projects/vitim/swafe/sw_wallet/node_modules/ethers/lib.esm/abi/abi-coder.js:203:16)
    at JsonRpcProvider.getRpcError (file:///home/pyro/dev/projects/vitim/swafe/sw_wallet/node_modules/ethers/lib.esm/providers/provider-jsonrpc.js:672:32)
    at file:///home/pyro/dev/projects/vitim/swafe/sw_wallet/node_modules/ethers/lib.esm/providers/provider-jsonrpc.js:298:45
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'CALL_EXCEPTION',
  action: 'call',
  data: null,
  reason: null,
  transaction: {
    to: '0x000000000000000000000000000000000000005d',
    data: '0xd9d47bb001'
  },
  invocation: null,
  revert: null,
  shortMessage: 'missing revert data',
  info: {
    error: { code: -32000, message: 'serialize: no public key available' },
    payload: {
      method: 'eth_call',
      params: [
        {
          to: '0x000000000000000000000000000000000000005d',
          data: '0xd9d47bb001'
        },
        'latest'
      ],
      id: 3,
      jsonrpc: '2.0'
    }
  }
}

May be I have to change parameters in provider.call?
How do I know the correct value for params.data?

Hello!
This error happens if you didn’t set the public key correctly on the validator. You need to get them from the KMS. A good way to start is to use our docker compose environment and replace the validator by your local instance. Just keep in mind that if you’re using a service running on your machine, you need to declare it as extra_hosts with the host-gateway keyword in docker compose and remove the fhevm-validator service.

For example, to use your own local validator, you can modify the docker compose with:

  gateway:
    image: ghcr.io/zama-ai/kms-blockchain-gateway-dev:v0.8.1-rc4
...
    environment:
...
      - GATEWAY__ETHEREUM__WSS_URL=ws://fhevm-localvalidator:8546
      - GATEWAY__ETHEREUM__HTTP_URL=http://fhevm-localvalidator:8545
...
    extra_hosts:
      - "fhevm-localvalidator:host-gateway"
    depends_on:
      kms-validator:
        condition: service_healthy

Hope it helps!