So i´ve been experimenting with Solidity and Remix and i wanted to and a simple while loop to the .transfer and .balance method. While being able to deploy the contract, I can´t seem to be able to send the 10 ether specified in the code. Any help would be much appreciated. Here is the code:

pragma solidity ^0.5.0;

    contract testTransfer {
        function Transfer () public payable {
        address payable x = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
        address payable myAddress = msg.sender;
        if (x.balance < 100 && myAddress.balance >= 10) x.transfer (10 ether);

a different version where myAddress = this; spits out the error that contract is not implicitly convertible to expected type

  • well what is the error you get? Does the account have 10 ether to send? – Lauri Peltonen Dec 12 '20 at 9:57
  • it has 10 ether and the error is that if i deploy it with a certain value then this happens: creation of testTransfer errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information. otherwise it deployes but no amount is being transferred. – GreyShadow94 Dec 12 '20 at 13:17
  • x.balance < 100 && myAddress.balance >= 10 im not sure that this is correct. balance return the balance of the Address in Wei – Majd TL Dec 18 '20 at 8:25

x.transfer(10 ether) transfers from the contract to x. If contract doesn't have enough ethers it will revert.

To obtain the contract's address use address payable myAddress = payable(address(this)).

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.