0

I feel this should be VERY SIMPLE. So code the Constructor to require an Amount and therefore that Amount will be then taken from the Metamask Wallet at the same time as the GasFees are paid for the Deployment.

But I simply cannot find a way to link the Amount field in the Constructor so that it takes the Ether from the Metamask Wallet during the Deployment.

I feel this will be a common requirement but simply I can't solve it.

I want it done as one action in order to save on Gas Fees.

So does anybody know how to do it and could they show me the code ?

Thanks,

H.

1 Answer 1

0

To send ether at deployment you have to make the constructor payable.

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 < 0.9.0;

contract Untitled {
    
    uint256 public x;
    
    constructor(uint256 _x) payable {
        x = _x;
    }
    
}

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.