alchemy-sdk-js icon indicating copy to clipboard operation
alchemy-sdk-js copied to clipboard

SDK core method call() does not support EIP-1898

Open cbm-egoubely opened this issue 2 years ago • 1 comments

Environment

  • Browser version: N/A (Node.js 16.x)
  • Alchemy SDK version: 2.2.1

Problem description

The SDK Core endpoint call does not support the syntax {"blockHash": "0x<some-hash>"} as second parameter though the docs explicitely mention it:

NOTE: the parameter is an object instead of a string and should be specified as: {"blockHash": "0x"}

cf. https://docs.alchemy.com/reference/sdk-call

How to reproduce:

const { Alchemy, Network } = require('alchemy-sdk');
const settings = {
  apiKey: "demo",
  network: Network.MATIC_MAINNET,
};

const alchemy = new Alchemy(settings);

const result = await alchemy.core.call({
    to: '0x02D158f550dd434526E0BC4a65F7DD50DDB9afEE',
    from: '0x9dA2192C820C5cC37d26A3F97d7BcF1Bc04232A3',
    data: '0x406f7f6f000000000000000000000000000000000000000000000000000000001460883c0000000000000000000000000000000000000000000000000000000003154b3a00000000000000000000000000000000000000000056da9d67d20d77090000000000000000000000000000000000000000000000000000000000000064920c48000000000000000000000000d01587ecd64504851e181b36153ef4d93c2bf93900000000000000000000000000000000000000001d471783ac9f1aea98bda2a6',
  }, { blockHash: '0xf1ade8878a02fa378129cb9444bb409c11e5f89b94444b5785b370a810268ee6' });

The following error is thrown:

Error: invalid blockTag
    at Formatter.blockTag (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/formatter.js:221:15)
    at AlchemyProvider.<anonymous> (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:2252:66)
    at step (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:48:23)
    at Object.next (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:29:53)
    at fulfilled (/Users/egoubely/projects/poc-alchemy/node_modules/@ethersproject/providers/lib/base-provider.js:20:58)

Note: it works if you Formatter.blockTag function from @ethersproject/providers to accept this format. It seems the fix has to be made on their side.

cbm-egoubely avatar Nov 15 '22 16:11 cbm-egoubely

There is an open issue on ethers: https://github.com/ethers-io/ethers.js/issues/2808

Do you know if there is a workaround until this get implemented? The RPC call works; I'm blocked only by the SDK validation.

cbm-egoubely avatar Nov 15 '22 17:11 cbm-egoubely

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

github-actions[bot] avatar Dec 16 '22 02:12 github-actions[bot]

@cbm-egoubely I'm looking into this issue now. Is there a reason you need to specifically pass call the method with the blockHash parameter?

The underlying ethers library also accepts block hashes as the 2nd parameter, and it will detect block hashes and convert them accordingly. The below code snippet works:

const settings = {
  apiKey: "demo",
  network: Network.MATIC_MAINNET,
};

const alchemy = new Alchemy(settings);

const result = await alchemy.core.call({
    to: '0x02D158f550dd434526E0BC4a65F7DD50DDB9afEE',
    from: '0x9dA2192C820C5cC37d26A3F97d7BcF1Bc04232A3',
    data: '0x406f7f6f000000000000000000000000000000000000000000000000000000001460883c0000000000000000000000000000000000000000000000000000000003154b3a00000000000000000000000000000000000000000056da9d67d20d77090000000000000000000000000000000000000000000000000000000000000064920c48000000000000000000000000d01587ecd64504851e181b36153ef4d93c2bf93900000000000000000000000000000000000000001d471783ac9f1aea98bda2a6',
  }, '0xf1ade8878a02fa378129cb9444bb409c11e5f89b94444b5785b370a810268ee6');

thebrianchen avatar Jan 30 '23 22:01 thebrianchen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

github-actions[bot] avatar Mar 02 '23 02:03 github-actions[bot]