I want to make a function call between a token (MyToken.sol) that inherits MintableToken.sol of OpenZeppelin and manipulate that token (Buy. Sol).


pragma solidity ^0.4.21;
import "https://github.com/OpenZeppelin/zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

contract MyToken is MintableToken {
  string public constant name = "MyToken";
  string public constant symbol = "MyToken";
  uint public constant decimals = 18;


pragma solidity ^0.4.21;
import "https://github.com/OpenZeppelin/zeppelin-solidity/contracts/ownership/Ownable.sol";
import "./MyToken.sol";

contract Buy is Ownable{
    MyToken my_token;

    function setToken( address _cotract_address ) public onlyOwner{
        my_token = MyToken( _cotract_address );

    function buyPoint( uint _amount ) public{       
        my_token.transfer( owner, _amount );

I call the transfer function inherited by MyToken from the buyPoint function. According to Remix of IDE, it seems that the transfer function is called by another thing set to my_token. Even if you call buyPoint after mint, revert() will be called because token is missing.

It is concrete procedure below.

  1. Deploy each contract

  2. Call the setToken function with the address of the deployed MyToken as an argument

  3. Mint with the same address as 2
  4. Call the buyPoint function → require (_value <= balances [msg.sender]); with revert

Before moving the step to the inside of the transfer function, it is confirmed that my_token contains normal data. If you step forward through the transfer function, there is no value that should be stored in balance, it is empty. As a result, revert () will be called by stuck on require.

Is the function call method incorrect? Can someone teach me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.