forked from MetaMask/metamask-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add live codeblocks with remark-codesandbox
- Loading branch information
Showing
7 changed files
with
1,638 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
# Integrate with MetaMask (API & SDK) | ||
# Integrate with MetaMask (API & SDK) | ||
|
||
This page shows how to integrate code blocks that will load up in a Codesandbox iframe | ||
|
||
```js codesandbox=vanilla?editorsize=75 | ||
document.getElementById('app').innerHTML = ` | ||
<button class="enableEthereumButton btn">Enable Ethereum</button> | ||
<button disabled class="sendEthButton btn">Send Eth</button> | ||
`; | ||
|
||
if (typeof window.ethereum !== 'undefined') { | ||
const ethereumButton = document.querySelector('.enableEthereumButton'); | ||
const sendEthButton = document.querySelector('.sendEthButton'); | ||
|
||
let accounts = []; | ||
|
||
//Sending Ethereum to an address | ||
sendEthButton.addEventListener('click', () => { | ||
ethereum.request({ | ||
method: 'eth_sendTransaction', | ||
params: [{ | ||
from: accounts[0], | ||
to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970', | ||
value: '0x29a2241af62c0000', | ||
gasPrice: '0x09184e72a000', | ||
gas: '0x2710', | ||
}], | ||
}) | ||
.then((txHash) => console.log(txHash)) | ||
.catch(console.error); | ||
}); | ||
|
||
ethereumButton.addEventListener('click', async () => { | ||
await getAccount(); | ||
sendEthButton.disabled = false; | ||
ethereumButton.disabled = true; | ||
}); | ||
|
||
async function getAccount() { | ||
accounts = await ethereum.request({ method: 'eth_requestAccounts' }); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
], | ||
} |
Oops, something went wrong.