0

I read the documentation of the changes on 0.5.0 but I do not know how to get this done with my code snippet. I tried to make the constructor payable but this does not work. Can someone help me. The line "wallet.transfer(msg.value) always through this error: "transfer" not found or not visible after argument-dependent lookup in address" I know that something changed with the namespaces but I cannot figure out how to workaround

contract WalletFactory {
    mapping(address => address[]) wallets;

    function newWallet(address _owner) payable public returns(address wallet) {
        wallet = (address)(new createWallet(msg.sender));
        wallets[msg.sender].push(wallet);
        wallet.transfer(msg.value);
    }
}

contract createWallet {
    address public owner;

    constructor(address _owner) payable public {
        owner = _owner;
    }
}

1 Answer 1

1

I made a few changes. Importantly, I added a payable fallback function to the Wallet contract (formerly called "createWallet"). (Otherwise it can't accept ether via transfer.) I also used the Wallet type everywhere possible rather than immediately casting to address. This is good for general type safety reasons.

pragma solidity 0.5.2;

contract WalletFactory {

    mapping(address => Wallet[]) wallets;

    function newWallet() payable public returns (Wallet wallet)
    {
        wallet = new Wallet(msg.sender);
        wallets[msg.sender].push(wallet);
        address(wallet).transfer(msg.value);
    }

}

contract Wallet {
    address public owner;
    constructor(address _owner) payable public {
        owner = _owner;
    }

    function() external payable { }
}

Your Answer

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

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