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

Add the wallet_switchEthereumChain method to the eip1193 transport #657

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

monomadic
Copy link

@monomadic monomadic commented Jul 8, 2022

This adds support for eip3326, calling wallet_switchEthereumChain. It will allow a dapp to request a chain switch for a user with a eip1193 transport (such as metamask).

There are other methods that go alongside this method, but I'm not sure if this is the canonical way to implement this into rust-web3, so I only implemented the smallest (simplest) method first.

To check the functionality (where 0x01 is the hexadecimal chain id for ethereum):

        let transport = Eip1193::new(self.provider.clone());
        transport.switch_chain("0x01")

I'm not sure if the return values are ideomatic to your api either. Any guidance would be helpful as these functions are critical for any user wishing to develop web3 dapps in rust with a eip1193 transport.

@monomadic
Copy link
Author

is this repository maintained any more? seems like there's open PRs from months back...


#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainId {
Copy link
Owner

Choose a reason for hiding this comment

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

Please move the struct declaration into the function, since I don't think it's required anywhere outside it (or just use json! internally)

Comment on lines +138 to +140
let js_params = JsValue::from_serde(&vec![&ChainId {
chain_id: chain_id.to_string(),
}])
Copy link
Owner

Choose a reason for hiding this comment

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

might be easier to use json! macro for such a simple parameter.

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

Successfully merging this pull request may close these issues.

None yet

2 participants