0
pragma solidity ^0.4.19;
contract Test {
    address one;

function Test(address _one) public {
    one = _one;
}

function send1() public payable {
    one.transfer(10);
}

function send2() public payable {
    require(msg.value > 0);
    one.transfer(msg.value);
}

function get() public view returns (address) {
    return one;
}

}

I'm trying do a simple smart contract in remix to transfer a fixed value of ether to the address 'one'. The funcion send2() is working but the function send1 is not. Thanks

  • 1
    What error are you getting when executing send1()? – pabloruiz55 Dec 11 '17 at 19:29
  • transact to browser/TestTransfer2.sol:Test.send1 errored: VM error: revert. revert The transaction has been reverted to the initial state. Debug the transaction to get more information. – Pedro Ferreira Dec 12 '17 at 10:48
0

My guess is that the function is actually working, but you are not noticing the ether being sent.

function send1() public payable {
    one.transfer(10);
}

The function above will transfer 10 wei. If you want to transfer 10 ether you should do:

function send1() public payable {
    one.transfer(10 ether);
}

Make sure that the contract has that kind of balance or that the function call is being passed such amount of value.

  • I tried that but is still not working. I think is because the message value is zero. – Pedro Ferreira Dec 12 '17 at 10:49
  • If the value is 0, are you making sure the contract has enough balance before calling the function? – pabloruiz55 Dec 12 '17 at 10:54

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.