Skip to content

Commit

Permalink
check for metamask. related to #235
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjv committed Dec 17, 2019
1 parent d32731f commit b3f5f01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
25 changes: 16 additions & 9 deletions examples/browser/ethereum/metamask-send-transaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ <h1>CAL + MetaMask: Sign a message (Ethereum)</h1>
<p><code>For errors and logs, check console</code></p>
<script>
/* global $, web3, Bundle */
const { Client, providers } = Bundle
const ethereum = new Client()
ethereum.addProvider(new providers.ethereum.EthereumMetaMaskProvider(web3.currentProvider))
ethereum.wallet.getAddresses().then(addresses => {
const from = addresses[0]
$('#send').click(() => {
ethereum.chain.sendTransaction(from, $('#toAddress').val() || undefined, $('#value').val(), $('#data').val()).then(result => {
$('#result').text(JSON.stringify(result))

if (typeof web3 === 'undefined') {
alert('Please install MetaMask.')
} else if (document.location.protocol === 'file:') {
alert('Due to browser security restrictions, MetaMask can\'t communicate with dapps running on file://. Please use a local server for development.')
} else {
const { Client, providers } = Bundle
const ethereum = new Client()
ethereum.addProvider(new providers.ethereum.EthereumMetaMaskProvider(web3.currentProvider))
ethereum.wallet.getAddresses().then(addresses => {
const from = addresses[0]
$('#send').click(() => {
ethereum.chain.sendTransaction(from, $('#toAddress').val() || undefined, $('#value').val(), $('#data').val()).then(result => {
$('#result').text(JSON.stringify(result))
})
})
})
})
}
</script>
</body>
</html>
28 changes: 18 additions & 10 deletions examples/browser/ethereum/metamask.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ <h1>CAL + MetaMask: Sign a message (Ethereum)</h1>
<p><code>For errors and logs, check console</code></p>
<script>
/* global $, web3, Bundle */
const { Client, providers } = Bundle
const ethereum = new Client()
ethereum.addProvider(new providers.ethereum.EthereumMetaMaskProvider(web3.currentProvider))
ethereum.wallet.getAddresses().then(addresses => {
const from = addresses[0]
$('#address').text(from)

$('#sign').click(() => {
ethereum.wallet.signMessage($('#message').val(), from).then(result => {
$('#result').text(JSON.stringify(result))
if (typeof web3 === 'undefined') {
alert('Please install MetaMask.')
} else if (document.location.protocol === 'file:') {
alert('Due to browser security restrictions, MetaMask can\'t communicate with dapps running on file://. Please use a local server for development.')
} else {
const { Client, providers } = Bundle
const ethereum = new Client()

ethereum.addProvider(new providers.ethereum.EthereumMetaMaskProvider(web3.currentProvider))
ethereum.wallet.getAddresses().then(addresses => {
const from = addresses[0]
$('#address').text(from)

$('#sign').click(() => {
ethereum.wallet.signMessage($('#message').val(), from).then(result => {
$('#result').text(JSON.stringify(result))
})
})
})
})
}
</script>
</body>
</html>

0 comments on commit b3f5f01

Please sign in to comment.