Switching Networks
This page describes how you can switch networks (secret type) using the web3 provider.
As seen in the advanced example of getting started, it is possible to provide a secretType when creating the web3 Venly provider. When you are connected to one network and want to switch to a different network:
  • call changeSecretType(secretType) on the provider, this returns a new instance of the provider
  • Re-initialize Web3: web3 = new Web3(provider);
  • If necessary, recreate subscriptions
  • Refresh wallets using web3.eth.getAccounts()(a user can have different wallets depending on the selected chain)
  • πŸŽ‰ All done!

Example

1
Venly.changeSecretType('BSC').then(provider => {
2
window.web3 = new Web3(provider);
3
window.web3.eth.getChainId().then(network => {
4
//returns the new chainId
5
});
6
window.web3.eth.getAccounts(function (err, wallets) {
7
//returns new wallets for given chain, update your UI accordingly
8
});
9
});
Copied!
​
​
Last modified 2mo ago
Copy link
Contents
Example