Replace ccipread.CCIPReadProvider with latest ethers
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?
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 https://github.com/ethers-io/ethers.js/issues/3240 to understand how to properly enable ccip-read, but if anyone here knows how to do this please let me know. Thanks.
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: https://github.com/smartcontractkit/ccip-read/pull/28