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

Venly.changeSecretType('BSC').then(provider => {
window.web3 = new Web3(provider);
window.web3.eth.getChainId().then(network => {
//returns the new chainId
});
window.web3.eth.getAccounts(function (err, wallets) {
//returns new wallets for given chain, update your UI accordingly
});
});