[Ethereum] Using sendTransaction in Web3.js


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")});

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) {
            value:  "1000000000000000000", 
            data: "0xdf"
                }, function(err, transactionHash) {
          if (!err)
            console.log(transactionHash + " success"); 

Related Topic