Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Explicitly add the chain Id to the JSONRPCPROVIDER #62

Merged
merged 2 commits into from
Nov 18, 2021

Conversation

aaronmgdr
Copy link
Member

Without this ether js JsonRPC provider seems to call a detectNetwork Function every event loop which makes a call the node like {method: eth_ChainID, params: [], id: randomNumber()}

Without this ether js JsonRPC provider seems to call a detectNetwork Function every event loop which makes a call the node like  {method: eth_ChainID, params: [], id: randomNumber()}
@vercel
Copy link

vercel bot commented Nov 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/c-labs/use-contractkit/84w85TSp1Texb9LoQKmkzLCQiurB
✅ Preview: https://use-contractkit-git-provider-netowrk-c-labs.vercel.app

const provider = kit.web3.currentProvider as unknown as ExternalProvider;
return useMemo(() => {
return new Web3Provider(provider);
return new Web3Provider(provider, {chainId: network.chainId, name: network.name});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but like linter says you'll need to update the memo list too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was wondering about your thoughts on moving the provider up into the App Context Provider. Or maybe its own ProviderProvider Context? so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment cuts out. What would be the benefit of the move?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One shared instance rather than each component that uses this having its own

…snt need to ask the node for this already known info
const nextKit = await getConnectedKit();
const nextProvider = nextKit.web3
.currentProvider as unknown as ExternalProvider;
return new Web3Provider(nextProvider).getSigner(nextKit.defaultAccount);
}, [kit.defaultAccount, getConnectedKit, signer]);
return new Web3Provider(nextProvider, { chainId, name }).getSigner(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyone know why this needs to be a new provider? why cant we reuse provider from userProvider?

@dckesler @jmrossy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexBHarley would probably be the best person to ask. I haven't reviewed this part thoroughly but it's entirely possible it was an oversight. No disrespect to Alex who overall did a great job but some parts were written hastily I think!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it a bit more, do you mean reuse the kit's provider? That's a Web3 provider, this creates an ethers.js provider

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Web3Provider(nextProvider, { chainId, name }) looks to give us same kind of thing as useProvider no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite understanding you I think. This is inside the useProvider hook.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is modifying 2 places. the useProvider and inside useGetConnectedSigner this line is inside the later

@aaronmgdr
Copy link
Member Author

relates to #63

@aaronmgdr aaronmgdr requested a review from dckesler November 15, 2021 17:36
Copy link
Contributor

@jmrossy jmrossy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dckesler dckesler merged commit 92bee01 into master Nov 18, 2021
@jmrossy
Copy link
Contributor

jmrossy commented Nov 26, 2021

@aaronmgdr I've tested this solution in Celo Wallet and haven't found it reduced the eth_chainId calls. I think the recommended fix is to use the StaticJsonProvider: ethers-io/ethers.js#901 (comment)

Though that may not work here before we need the provider to respond to network changes (like in Metamask) cc @dckesler

@nicolasbrugneaux nicolasbrugneaux deleted the provider-netowrk branch January 12, 2022 16:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants