Web3.js – How to Use sendTransaction for Ethereum DApps

ethereum-wallet-dappweb3js

I'm trying to make a function in my Dapps front end that requests Ether from the user, I know I have to use web3.eth.sendTransaction() but am unsure of how to correctly implement and call this function on the front end of my Dapp, thanks!

current code is:

   $("#button").click(function() {
    Raffle.main(function (err, result) {
      web3.eth.sendTransaction({from:0x627306090abaB3A6e1400e9345bC60c78a8BEf57 ,to:0x086912faa7f6598d28d80c448c8d1e9dae5a4dee, value:web3.toWei(1, "ether")});
      console.log(result);
      });

Best Answer

I found this to work to call a function and send Ether with it, to is my contracts address, value is the amount in wei I want to send with it and data is the address of my function that I want to call when sending the data

  function mainEnter() {
        web3.eth.getAccounts(function(error, result) {
        web3.eth.sendTransaction(
            {from:web3.eth.accounts[0],
            to:"0x943",
            value:  "1000000000000000000", 
            data: "0xdf"
                }, function(err, transactionHash) {
          if (!err)
            console.log(transactionHash + " success"); 
        });
    });

    }