Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ccipread.CCIPReadProvider with latest ethers #27

Open
tfalencar opened this issue Aug 9, 2022 · 2 comments
Open

Replace ccipread.CCIPReadProvider with latest ethers #27

tfalencar opened this issue Aug 9, 2022 · 2 comments

Comments

@tfalencar
Copy link

tfalencar commented Aug 9, 2022

Please correct me if I'm wrong, but since ccip-read support has already landed on ethers-js, it should be possible to drop the "@chainlink/ethers-ccip-read-provider" package from 'examples/trusted-gateway-token/client/src/index.ts', and use purely ethers-js.

Furthermore since CCIP-read is a protocol, I'd expect the examples here to work interchangeably with ethers. Even the @chainlink/ethers-ccip-read-provider project description itself says it is deprecated in favour of ethers and users should use ethers instead.

I've tried replacing @chainlink/ethers-ccip-read-provider with ethers in the example client, but didn't have success thus far.

Are there incompatibilities between this demo and the way CCIP-read is implemented in ethers-js?

@tfalencar
Copy link
Author

In my first attempt, it seems ethers.js halts on the first exception thrown from the smartcontract (instead of proceeding with the lookups based on the provided URLs from the exception).

I've created ethers-io/ethers.js#3240 to understand how to properly enable ccip-read, but if anyone here knows how to do this please let me know. Thanks.

@tfalencar tfalencar changed the title Replacing ccipread.CCIPReadProvider with latest ethers yields error Replace ccipread.CCIPReadProvider with latest ethers Aug 9, 2022
@tfalencar
Copy link
Author

tfalencar commented Aug 9, 2022

Ok, I managed to get it working using only ethers, but its a little bit weird:

First the provider needs to override an internal method, like this:

class MyCustomProvider extends providers.JsonRpcProvider {
  async ccipReadFetch(tx: Transaction, calldata: string, urls: Array<string>): Promise<null | string> {
    urls = urls.filter((u: any) => isSafeUrl(u));
    return super.ccipReadFetch(tx, calldata, urls);
  }
}

function isSafeUrl(url: string): boolean {
  console.log(`Allowing ${url}`);
  return true;
}

const provider = new MyCustomProvider(PROVIDER_URL);

Then, for the "balanceOf" calls, I had to add the { ccipReadEnabled: true} parameter (otherwise ethers would not make the subsequent requests.

However, the transfer method call fails if I add { ccipReadEnabled: true } to it. So by removing, I noticed it works (I'm guessing write operations doesn't need to specify ccipReadEnabled?).

Since there is no documentation about this in ethers yet, I'm not sure if this is a bug or not. In any case, I've uploaded the changes to the following: #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant