Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

63
Views
Transfer ether from a contract address to an actual Ethereum address

I'm trying to send ether from a contract address generated by Truffle and use it as a sender to an Ethereum address (the current injected Metamask account). I already have transferred the ether from a source wallet to a contract using Truffle console, and I tried to copy the address of the contract and use it in web3.sendTransaction method in Web3JS. However, the console.log yields the following error:

Invalid parameters: must provide an Ethereum address.

This is my Javascript code:

// transfer ether fxn (requires callback function)
function transfer () {
  var callback = function(error, res) {
    if(!error) {
        console.log(res);
    }
    else {
        console.log(error);
    }
  }

  web3.eth.sendTransaction({
    to: web3.eth.accounts[0], // current injected Metamask account on the DApp
    from: '0x6509ee304ec8476cfa7e9074f2be5fcfb18e18b4', // the contract address from Truffle, yields the invalid parameters error
    value: web3.toWei('0.01', 'ether')
  }, callback);

}
8 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs