-2

with my own 0x363.. wallet address I am generating erc20 token and when I issue this erc20 contract a contract address is generated (0x966D...). that is, I have one wallet address and one coin address.

E.g: 1 mytoken = 1 ethereum

E.g: If a user buys my token with metamask, the user will pay ethereum. And where is 1 ethereum. Why is this ethereum not uploaded to my admin account (0x363..). this ethereum goes to erc20 (0x966D ..) as far as I understand. How can I get this ethereum to my admin account?

srdpnr
  • 3
  • 1
  • 1
  • 2
    Stackoverflow is for questions about programming; the [stackexchange devoted specifically to Ethereum](https://ethereum.stackexchange.com) would be a much better place to ask about things like this. – Gordon Davisson Dec 23 '21 at 01:14

1 Answers1

0

How can I get this ethereum to my admin account?

Based on the context of the question (the ETH is paid to the token contract - not to a DEX pair contract), I'm assuming you have a custom buy function.

You can expand this buy function to use the transfer() method of address payable to transfer the just received ETH to your admin address.

pragma solidity ^0.8;

contract MyToken {
    address admin = address(0x123);

    function buy() external payable {
        // transfers the whole ETH `value` sent to the `buy()` function
        // to the `admin` address
        payable(admin).transfer(msg.value);

        // ... rest of your code
    }
}

Contract bytecode is immutable (with some edge case exceptions), so in order to perform the change, you'll need to deploy a new contract - can't expand the already deployed contract.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100