When deploying a smart contract to a private network, how to send ERC20 token (on the same private network) in msg.value to the smart contract in constructor?
Here is the contract:
pragma ^0.7.0;
interface ERC20 {
//standard ERC20 functions
}
contract MyContract () {
address erc20Contract;
uint256 value;
constructor (address _erc20) {
ERC20 token = ERC20(_erc20); //_erc20 is the deployed address of ERC20 token
erc20Contract = _erc20;
//need to transfer msg.value token to the contract
value = msg.value; //<<==how to transfer msg.value to the contract with ERC20 function, such as token.transfer()?
}
}
msg.value?" - That's an oxymoron, sincemsg.valuedenotes the amount of ether included in the transaction. – goodvibration Dec 27 '20 at 09:27msg.value, does it mean thatERC20token.transfer()has already done before submitting transaction withmsg.value? So if it is dapp submitting a transaction, then dapp needs to doERC20token.transfer()before calling contract constructor with themsg.value. Isn't it? – user938363 Dec 27 '20 at 16:53msg.value, when the transfer of token in qty ofmsg.valueneeds to happen for the transaction?. – user938363 Dec 27 '20 at 16:57msg.valuehas nothing to do with ERC20 transfer. – goodvibration Dec 27 '20 at 16:57goodvibration, the smart contract needs to hold token invalue, the transfer of the token to the smart contract needs to happen. I thought calling constructor withmsg.valueand token transfer can happen at the same time in constructor. But it seems not correct. – user938363 Dec 27 '20 at 17:04