1

I'm trying to send LINK (erc20) and Ether (goerli in this case) to my contract on deployment. I understand how to do this for native/testnet ether. But how do I combine them to send erc20 and ether at the same time, whenever I deploy my contract? I have already set approval prior to deployment for the token to spend signer's LINK

Current deployment code:

            let factory = new ethers.ContractFactory(abi, bytecode, signer);
            let contract = await factory.deploy(
                arg1,
                arg2,
                ..., 
                { 
                    value: ethers.utils.parseEther("0.00001")
                }
            );
3
  • If you already set approval then your contract can use LINKs belong to sender. Why do you need to "send" link during deployment ? "sending" here means the code in your constructor call "send" in Link Contract ? Could you clarfiy more the reason, the use case and your constructor code ?
    – minhhn2910
    Dec 26, 2022 at 5:01
  • afaik you would need a second transaction to send the tokens as is a separate contract. Hope it helps
    – donoso.eth
    Dec 26, 2022 at 8:09
  • @minhhn2910 I ultimately need to use those tokens for using a Chainlink function (which requires LINK). And I also want the user to send an amount of Ether to the contract to pay for gas later on. As they both will require a gas fee, I was hoping that there would be a method to transfer both at the same time.
    – gggggggggg
    Dec 26, 2022 at 13:36

2 Answers 2

2

Seems you already know how to send ethers to the contract and to send some erc20 as well during deployment, you can modify the constructor to transfer the link tokens while deployment. The code would look something like this.

constructor(uint256 linkAmount){
    IERC20(0x).transferFrom(msg.sender, address(this), linkAmount);
    // rest of code
}

Hope this helps!

1
  • That gives me the error: execution reverted whenever trying to deploy the contract. An example of a transaction that failed this way is: goerli.etherscan.io/tx/…
    – gggggggggg
    Dec 27, 2022 at 14:38
0

If I am not mistaken, to send both Ether and an ERC20 token to a contract at deployment, you can use the transferAndCall function provided by the ERC223 standard. This function allows you to send both Ether and an ERC20 token in a single transaction. have a look at https://github.com/ethereum/EIPs/issues/677

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.