I am trying add the front end part of a payable function using web3.js (And just vanilla JavaScript, no other libraries).

Here is the solidity function:

    function deposit() public payable {
        balance[msg.sender] += msg.value;

Here is a picture of the front end: DAPP Front End

I have created a contract for the withdrawal.

function withdraw() {
            amount = withdrawInput.value * 1000000000000000000;
            contract.withdraw(amount, function (err, result) {
                if (err) {
                    console.log('An error occured', err);
                } else {
                    console.log('You have successfully withdrawn ' + amount / 1000000000000000000 +
                                ' ether to your wallet.');

But I am completely lost on how to set the transaction value to the amount set in the input. Oh, if it helps the HTML element ID's important for the deposit function are "depositInput" (to set transaction value) and "depositButton" (To call the function).

  • 1
    So the problem is how to set the value for the deposit function?, also you wrote "I have created a contract for the withdrawal." but then you show javascript code, can you please clarify?
    – Jaime
    Commented Jul 5, 2018 at 11:47
  • Yes, I do not know how to call the solidity deposit () payable function using web3.js Commented Jul 5, 2018 at 18:56

1 Answer 1


You can specify the deposit value like this:

contract.deposit({'value': put_here_deposit_inputvalue_in_wei}, function (err, result){ }

Hope this help

  • 1
    your answer is really helpful, it should have more upvotes so others can find it quickly unlike me. Commented Oct 27, 2019 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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