0

I am having a problem with my smart contract making value transfers. My current environment:

Truffle v5.0.3 (core: 5.0.3)
Solidity v0.5.0 (solc-js)
Node v10.13.0
pragma solidity >=0.4.21 < 0.6.0;

contract ContractWallet {
    constructor() public{
    }
}

contract deposit {
    mapping (address=>ContractWallet) public users;

    constructor () public { }

    function testDeposit(
    )
        public
        payable
    {
        ContractWallet _newWallet = new ContractWallet();
        address(_newWallet).transfer(msg.value);
        users[msg.sender] = _newWallet;
    }

}

After creating a contract from a contract, I can not transfer ether to the newly created contract address. I think I'll probably add 'payable', but I don't know how to do it.

  • You need to add a payable external function in the ContractWallet declaration. function () external payable { }. – Briomkez Mar 25 at 10:38
  • Or more likely, replace function testDeposit with this function. – goodvibration Mar 25 at 10:38
  • I solved it after adding apayable external function in the ContractWallet. Thank you!! – kohei tanaka Mar 26 at 1:29
0

You probably need to add fallback function to your deposit smart contract like this:

function () public payable {
    testDeposit ();
}

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.