Skip to content

Commit

Permalink
Add switchEthereumChain button (#102)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Marks <[email protected]>
  • Loading branch information
brad-decker and rekmarks authored Jun 25, 2021
1 parent 296cad8 commit e3d1ff0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,21 @@ <h4>
<div class="card">
<div class="card-body">
<h4 class="card-title">
Add Ethereum Chain
Ethereum Chain Interactions
</h4>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="addEthereumChain"
disabled
>
xDAI
Add xDAI Chain
</button>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="switchEthereumChain"
disabled
>
Switch to xDAI Chain
</button>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const signTypedDataV4VerifyResult = document.getElementById('signTypedDataV4Veri

// Miscellaneous
const addEthereumChain = document.getElementById('addEthereumChain')
const switchEthereumChain = document.getElementById('switchEthereumChain')

const initialize = async () => {
try {
Expand Down Expand Up @@ -185,6 +186,7 @@ const initialize = async () => {

if (isMetaMaskInstalled()) {
addEthereumChain.disabled = false
switchEthereumChain.disabled = false
} else {
onboardButton.innerText = 'Click here to install MetaMask!'
onboardButton.onclick = onClickInstall
Expand Down Expand Up @@ -217,6 +219,15 @@ const initialize = async () => {
})
}

switchEthereumChain.onclick = async () => {
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{
chainId: '0x64',
}],
})
}

const initializeAccountButtons = () => {

if (accountButtonsInitialized) {
Expand Down

0 comments on commit e3d1ff0

Please sign in to comment.