Very new to EJS and trying to figure this out. Posting here after trying for few hours. I am able to send an amount of ETH to a contract but don't have an option to choose how much.

Trying to find a way to be able to enter the amount of eth to be sent before sending using Metamask.

Here is the code.

<!doctype html>
    <title>USE MetaMask</title>


    <a href="https://github.com/MetaMask/TipButton">View on Github</a>
    <div class="tip-button"></div>
    <div class="message"></div>

var MY_ADDRESS = '0x82462c60EC0e82AF991B93E82D3B1Ab5f20D30F4'
var tipButton = document.querySelector('.tip-button')
tipButton.addEventListener('click', function() {
  if (typeof web3 === 'undefined') {
    return renderMessage('<div>You need to install <a href=“https://metmask.io“>MetaMask </a> to use this feature.  <a href=“https://metmask.io“>https://metamask.io</a></div>')
  var user_address = web3.eth.accounts[0]
    to: MY_ADDRESS,
    from: user_address,
    value: web3.toWei('1', 'ether'),
    gas: 302575,
    gasPrice: 30000000000,
  }, 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

  • what is the problem? What error are you getting? – Josh Pittman Feb 19 '18 at 11:29
  • the field value is the one you need to change. You can send an amout of Wei that you can calculate from other subcurrencies. web3.toWei('1','ether') will return the amount of one ether in Wei; – Kaki Master Of Time Feb 19 '18 at 11:37

Here in your Script you have hard coded the value to be 1.

value: web3.toWei('1', 'ether');

So it will be sending 1 ETH every time.

Take the value set it later using JavaScript.

A basic JS tutorial like this might help you.

  • @AddyTiger Consider accepting the answer if it helped – Achala Dissanayake Mar 11 '18 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.