0

A bit new to ETH development. I am trying to create a contract that helps me receive tokens of a particular address on the ETH network. For testing purposes, I am creating my own Token on the testnet using the OpenZeppelin implementation.

pragma solidity ^0.8.0;

import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol';

contract Token is ERC20{
    address public admin;
    constructor() ERC20('MyToken', 'MTN'){
        _mint(msg.sender, 10000 * 10 ** 18);
        admin = msg.sender;
    }

    function mint(address to, uint ammount) external{
        require(msg.sender == admin, "Only Admin Can Mint");
        _mint(to, ammount);
    }

    function burn(uint ammount) external {
        _burn(msg.sender, ammount);
    }

}

For my contract, I am checking the address of the token being sent to validate the transaction.

function enter() public payable {
    
    IERC20 token = IERC20(`0x123`); // Insert the token contract address instead of `0x123`
    require(token.transferFrom(msg.sender, address(this), .01 ether));
}

My question is on the testnet, how do I know what the contract address of this newly created token is?

3 Answers 3

0

The contract address of the token will depend on the specific network you are deploying it onto. Generally, the contract address can be found in the output of the command you are using to deploy the token on the testnet.

For example, if you are deploying the token on the Ethereum mainnet, you can use the command truffle migrate to deploy it, and the output will contain the contract address of the token.

0

what IDE did you use to deploy the contract address? , is it remix or vscode if it's remix go to the deploy and run transaction tab it should be there and if it's vscode it depends on the tool, basically, you should see the contract address in the terminal, if you can't do this, get the address that deployed the contract address, now depending on the testnet e.g go to its block explorer from there you should be able to trace the address to the contract address it deployed

I would have commented and asked for specific details but I don't have enough reputation yet

0

You can use the deploy method provided by your Ethereum client (e.g. Truffle or web3.js) to deploy your contract to the testnet and retrieve the contract address.

For example, in Truffle, you can use the following command to deploy your contract:

truffle deploy --network <testnet-name>

This will deploy your contract to the specified testnet and return the contract address in the console output.

Once you have the contract address, you can use it in your contract's enter function as follows:

function enter() public payable {
    
    IERC20 token = IERC20(`<contract-address>`);
    require(token.transferFrom(msg.sender, address(this), .01 ether));
}

You can also use the Ethereum block explorer for your testnet to view the contract address of your deployed contract.

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.