Skip to content

Instantly share code, notes, and snippets.

@ksaitor
Last active November 4, 2024 15:18
Show Gist options
  • Select an option

  • Save ksaitor/6c832c106a8b9aee4f76a9145eb5d764 to your computer and use it in GitHub Desktop.

Select an option

Save ksaitor/6c832c106a8b9aee4f76a9145eb5d764 to your computer and use it in GitHub Desktop.

Revisions

  1. ksaitor revised this gist Dec 26, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ethereum-payment-metamask.html
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    await ethereum.enable();
    initPayButton()
    } catch (err) {
    console.log('User denied account access', err)
    $('#status').html('User denied account access', err)
    }
    } else if (window.web3) {
    window.web3 = new Web3(web3.currentProvider)
  2. ksaitor revised this gist Dec 26, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ethereum-payment-metamask.html
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@

    const initPayButton = () => {
    $('.pay-button').click(() => {
    // paymentAddress is where funds will be send to
    const paymentAddress = '0x192c96bfee59158441f26101b2db1af3b07feb40'
    const amountEth = 1

  3. ksaitor revised this gist Dec 26, 2018. 1 changed file with 32 additions and 20 deletions.
    52 changes: 32 additions & 20 deletions ethereum-payment-metamask.html
    Original file line number Diff line number Diff line change
    @@ -9,30 +9,42 @@
    <div id="status"></div>
    </div>
    <script type="text/javascript">
    $(() => {
    if (typeof web3 !== 'undefined') {
    $('.pay-button').click(() => {

    const paymentAddress = '0x192c96bfee59158441f26101b2db1af3b07feb40'
    const amountEth = 1

    web3.eth.sendTransaction({
    to: paymentAddress,
    value: web3.toWei(amountEth, 'ether')
    }, (err, transactionId) => {
    if (err) {
    console.log('Payment failed', err)
    $('#status').html('Payment failed')
    } else {
    console.log('Payment successful', transactionId)
    $('#status').html('Payment successful')
    }
    })
    })
    window.addEventListener('load', async () => {
    if (window.ethereum) {
    window.web3 = new Web3(ethereum);
    try {
    await ethereum.enable();
    initPayButton()
    } catch (err) {
    console.log('User denied account access', err)
    }
    } else if (window.web3) {
    window.web3 = new Web3(web3.currentProvider)
    initPayButton()
    } else {
    $('#status').html('No Metamask (or other Web3 Provider) installed')
    }
    })

    const initPayButton = () => {
    $('.pay-button').click(() => {
    const paymentAddress = '0x192c96bfee59158441f26101b2db1af3b07feb40'
    const amountEth = 1

    web3.eth.sendTransaction({
    to: paymentAddress,
    value: web3.toWei(amountEth, 'ether')
    }, (err, transactionId) => {
    if (err) {
    console.log('Payment failed', err)
    $('#status').html('Payment failed')
    } else {
    console.log('Payment successful', transactionId)
    $('#status').html('Payment successful')
    }
    })
    })
    }
    </script>
    </body>
    </html>
  4. ksaitor revised this gist Dec 26, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ethereum-payment-metamask.html
    Original file line number Diff line number Diff line change
    @@ -19,12 +19,12 @@
    web3.eth.sendTransaction({
    to: paymentAddress,
    value: web3.toWei(amountEth, 'ether')
    }, (err, data) => {
    }, (err, transactionId) => {
    if (err) {
    console.log('Payment failed', err)
    $('#status').html('Payment failed')
    } else {
    console.log('Payment successful', data)
    console.log('Payment successful', transactionId)
    $('#status').html('Payment successful')
    }
    })
  5. ksaitor created this gist Dec 26, 2018.
    38 changes: 38 additions & 0 deletions ethereum-payment-metamask.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
    <div>
    <button class="pay-button">Pay</button>
    <div id="status"></div>
    </div>
    <script type="text/javascript">
    $(() => {
    if (typeof web3 !== 'undefined') {
    $('.pay-button').click(() => {

    const paymentAddress = '0x192c96bfee59158441f26101b2db1af3b07feb40'
    const amountEth = 1

    web3.eth.sendTransaction({
    to: paymentAddress,
    value: web3.toWei(amountEth, 'ether')
    }, (err, data) => {
    if (err) {
    console.log('Payment failed', err)
    $('#status').html('Payment failed')
    } else {
    console.log('Payment successful', data)
    $('#status').html('Payment successful')
    }
    })
    })
    } else {
    $('#status').html('No Metamask (or other Web3 Provider) installed')
    }
    })
    </script>
    </body>
    </html>