0

Im trying to make a transfer ownership example by transferring ownership by sending ether. I've been trying to use msg.value and transfer() to send ether from owner B to owner A so owner B can take ownership.

address public previousOwner;
address public currentOwner;
uint public txTimeStamp;
event transferred();

function transfer() external payable onlyOwnerB {
     require (msg.value == 1 ether);
     ownerA.transfer(1 ether);
     previousOwner = ownerA;
     currentOwner = ownerB;
     txTimeStamp = now;
     emit transferred();
}

I also have a fallback function to receive funds:

function receiveTxPay() public payable returns (bool) {
     return true;
}

I'm using the Remix compiler in a Javascript VM, where owner A is one of the addresses and owner B is another. I made sure to call the transfer() function as owner B. But whenever I call the function i get a "transact to Contract.transfer() errored: VM error: revert." error. I've also tried just using the require(msg.value == 1 ether) line, and also just using the transfer() line. Trying all of these returns the same error message.

0

Both of those lines will fail if you haven't sent 1 ether to the contract as part of your transaction, so I assume you're not doing that. You need to set the "value" field in the upper right to 1 ether. (Make sure you type 1 in the text field and choose ether from the dropdown to its right.)

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.