diff --git a/index.html b/index.html
index da228b6..0669df6 100644
--- a/index.html
+++ b/index.html
@@ -39,26 +39,33 @@
MetaMask Tip Button Example
var tipButton = document.querySelector('.tip-button')
-tipButton.addEventListener('click', function() {
+tipButton.addEventListener('click', async function() {
- if (typeof web3 === 'undefined') {
+ if (typeof ethereum === 'undefined') {
return renderMessage('')
}
- var user_address = web3.eth.accounts[0]
+ const accounts = await ethereum.request({method:'eth_requestAccounts'})
+ var user_address = accounts[0]
+
+ try {
+ const transactionHash = await ethereum.request({
+ method: 'eth_sendTransaction',
+ params: [
+ {
+ 'to': MY_ADDRESS,
+ 'from': user_address,
+ 'value': '0x11c37937e08000',
+ },
+ ],
+ })
+ // Handle the result
+ console.log(transactionHash)
+ } catch (error) {
+ console.error(error)
+ }
- 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) {