2

Is it possible to implement a payable function and transfer msg.value to another address immediately?

function purchase() payable public {
  //transfer msg.value
}

I'm thinking this wouldn't work because the ether hasn't completely arrived in the smart contract yet.

2 Answers 2

1

nope, works just fine. Smart contracts are pretty amazing

function purchase() payable public {
  owner.transfer(msg.value);
}
2

As the previous mentioned, this work just fine. Although you need to typecast the receiving address to be payable, since the addresses and functions expecting a payment should be marked payable.

function purchase() payable public {
  payable(receivingAddress).transfer(msg.value);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.