Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active June 21, 2022 22:38
Show Gist options
  • Save anthonybudd/32cf18e00414e52a9d115508348dcd56 to your computer and use it in GitHub Desktop.
Save anthonybudd/32cf18e00414e52a9d115508348dcd56 to your computer and use it in GitHub Desktop.
if (typeof window.ethereum === 'undefined') {
this.$notify({
title: "window.ethereum is undefined. Have you installed MetaMask?",
type: 'error'
})
console.error('window.ethereum', typeof window.ethereum);
return;
}
ethereum.enable().then((accounts) => {
var account = accounts[0];
ethereum.sendAsync({
method: 'eth_sendTransaction',
params: [{
from: account,
to: '0x9ad1363b665a9B7946dccF20E465De944E68538f',
value: '37000000'
// value: web3.toWei("0.037", "ether") // Tried, doesn't work
// value: "0x01" // Found in: https://github.com/MetaMask/web3-provider-engine/blob/20eeb02e9a809e70ec9100a3819819ad2e06f51b/test/wallet.js#L61
// value: "0x9184e72a" // Found in: https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#ethereum.sendasync
}],
}, (err, result) => {
if (err) {
console.error(err);
if (err.message) this.$notify({
title: err.message,
type: 'error'
})
}
console.log(result)
})
}).catch((err) => {
console.error(err);
if (err.message) this.$notify({
title: err.message,
type: 'error'
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment