0

I am simple man, but learning Eth Dev.

I am testing a contract in Remix however I can't transfer Eth between the accounts in the javascript VM (using solidity V0.6.0 +). I have researched for a while but most implementations are in version 0.4. and i don't see the point in developing my smart contract on old versions especially considering secutiry and the great contracts made by Open Zeppelin.

So breaking my issue down to basic questions...

How do I transfer ethereum between accounts in REMIX JavaScript VM using solidity V0.6.0+?

All i want to do is send 1 ether from the user to the contract owner from (ownable.sol).From there I can build the logic i want for the actual contract.

 function Fund() public payable{
        address(owner).transfer(1 ether);
    }

Where am I going wrong?!

0

You can transfer Ether from the contract by making the to address payable and the unit of transfer will be wei by default,

    function Fund(address payable _toAddress, uint256 _amountInWei) 
    external payable {
        address myAddress = address(this);
        if (myAddress.balance >= _amountInWei) {
            _toAddress.transfer(_amountInWei);
        }
    }

2
  • Huge thanks for the reply @Noushad. I can get it to compile but the wei transfer doesn't work I enter a value (and address to send it too) but the wei value remains 0. This is what I get in the console. ' from 0x1e8a23b4009 to coinA.Fund(address,uint256) 0x05aaf52e09e3 gas 3000000 gas transaction cost 23960 gas execution cost 1024 gas input 0xda8...02710 decoded input { "address _toAddress": "0x1228d1906b46b971b71fA363bd5a4c7FCc520e09", "uint256 _amountInWei": { "_hex": "0x2710" } } decoded output {} logs [] value 0 wei <<< still @ zero :( ' – Waving_From_Heights May 8 '20 at 6:43
  • does your contract have ether balance to send ? Can you check it by this function, function balanceInContract() public view returns(uint256) { address myAddress = address(this); return myAddress.balance; } – Noushad Mohamed May 8 '20 at 7:06
0

You cannot have the contract transfer ether on behalf of address A to another address B unless A approves the contract to do so! I asked a similar question in the past which might be helpful to you!

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.