1

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);
                    loadAccount();
                } else {
                    console.log('You have successfully withdrawn ' + amount / 1000000000000000000 +
                                ' ether to your wallet.');
                    loadAccount();
                };
            });
        };

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 Jul 5 '18 at 11:47
  • Yes, I do not know how to call the solidity deposit () payable function using web3.js – BlockchainBoy Jul 5 '18 at 18:56
2

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. – Zeeshan Ahmad Khalil Oct 27 at 12:16

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.