Hoping someone can assist me. I have a contract I deployed and verified on the Goerli testnet. Its a simple ERC20 contract (contract myToken is ERC20) in which I minted all the coins to the deployer address upon deployment. Here is the contract on etherscan…. https://goerli.etherscan.io/address/0xA56AfB65Df413F36f9c753c2e8E56249a44AB812#code
Now I would like to deploy a 2nd contract in which i create a few functions that call approve and transferFrom (since my previous token contract "is ERC20") so I can transfer those tokens into this contract pasted here below and ultimately call this drop function.... https://goerli.etherscan.io/address/0x873289a1aD6Cf024B927bd13bd183B264d274c68#code
In other words I would like to create a 2nd contract to interact with my previous token contract and basically use this new contract to transfer tokens to this other contract. I am using the same account and private key that deployed my previous token contract and this new contract and I do have the ERC20 tokens in personal account balance (not the token contract). Before I show my deploy scripts (using hardhat) can someone tell me if my solidity file contract looks set up correctly?
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface Bucket {
function drop(address erc20, uint256 amount) external;
}
contract EmitWinner {
address hoetokenAddress = 0xA56AfB65Df413F36f9c753c2e8E56249a44AB812;
address bucketAddress = 0x873289a1aD6Cf024B927bd13bd183B264d274c68;
ERC20 erc20 = ERC20(hoetokenAddress);
function approve(uint256 _amount) public {
erc20.approve(bucketAddress, _amount);
}
function drop(uint _amount) external payable {
bool success = ERC20(erc20).transferFrom(msg.sender, bucketAddress, _amount);
require(success, "Transaction Failed");
Bucket(bucketAddress).drop(msg.sender, _amount);
}
}
To be clear i am calling approve and transferFrom functions from the deployer/msg.sender account and giving the bucketAddress the permission to approve and transfer my tokens. I am not giving this contract here the approval to call TransferFrom. Is that the correct way to do this? Don't I want to give the bucketAddress the approval and the ability to call TransferFrom?
approve()
function specifically from the token contract only, or the approval will be given from the contract rather the user.