MetaMask Tip Button Example
var MY_ADDRESS = '0x85eF572AB2ceADE247Ef1E5bF340EA0B8801B584'
var tipButton = document.querySelector('.tip-button')
tipButton.addEventListener('click', function() {
if (typeof web3 === 'undefined') { return renderMessage('
') }
var user_address = web3.eth.accounts[0]
web3.eth.sendTransaction({ to: MY_ADDRESS, from: user_address, value: web3.toWei('1', 'ether'), }, function (err, transactionHash) { if (err) return renderMessage('There was a problem!: ' + err.message)
// If you get a transactionHash, you can assume it was sent, // or if you want to guarantee it was received, you can poll // for that transaction to be mined first. renderMessage('Thanks for the generosity!!') }) })
function renderMessage (message) { var messageEl = document.querySelector('.message') messageEl.innerHTML = message }