0

I deployed this ERC-20 contract https://github.com/sijo0703/solidity-contracts/blob/master/MyToken.sol in Remix via the JavaScript VM.

How can I transfer some Tokens from the contract creator's address (me) to another address from within Remix? When I call the Transfer function using the Orange Button it fails. I assume the Transfer function is being called using the Contract address which has no Tokens.

How can I initiate the Transfer function via the contract creator's address (me) from within the Remix IDE?

Thank you

1 Answer 1

0

After deploying the ERC-20, your address receives the total supply of the token, as you can see here :

    constructor( uint256 _totalSupply) public{
    totalSupply_ = _totalSupply;
    balances[msg.sender] = totalSupply_;
}

_totalSupply is a constructor parameter so you have to fulfill the corresponding section in Remix. Be aware of the decimal system of the ERC-20 : if you want 10000 units with 3 decimals, _totalSupply will be equal to 10000*10^3 (more info here : Decimals on ERC20 Tokens).

When I call the Transfer function using the Orange Button it fails. I assume the Transfer function is being called using the Contract address which has no Tokens.

The contract address does not need tokens, the sender (you in this case) does. In addition you need some ETH to pay the gas fees.

How can I transfer some Tokens from the contract creator's address (me) to another address from within Remix?

Just call transfer with the same address that the one you used to deploy. Be sure to respect the following condition :

require(numTokens <= balances[msg.sender]);

Send an amount <= your balance which is equal to the token total supply after the deployment.

6
  • "Just call transfer with the same address that the one you used to deploy. Be sure to respect the following condition" This is what I don't know how to do in Remix. I don't know how to specify the calling address... the default address is the contract address. Too bad I can't paste screenshots here.
    – Axium7
    Commented Sep 29, 2020 at 13:37
  • I figured it out. I thought the Account was just for showing me the available addresses but the chosen account is what actually executes the transactions. I understand now. Thank you.
    – Axium7
    Commented Sep 29, 2020 at 13:44
  • Yes, that's it.
    – clement
    Commented Sep 29, 2020 at 13:45
  • I deployed my contract to Rinkeby. Everything works fine. However, I noticed when I perform a TransferFrom transaction and allowance reaches 0, I get a Gas Estimation Error in Remix. Shouldn't Remix allow the transaction to go through and then "require(numTokens <= allowed[owner][msg.sender]);" should trap the Error?
    – Axium7
    Commented Sep 30, 2020 at 5:58
  • I think I figured out this one too. At the end of the message it says "always failing transaction". So this message combines both running out of Gas and a heads up that your Transaction will always fail.
    – Axium7
    Commented Sep 30, 2020 at 7:00

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.