When I try to create a new instance of the standard token, compiler throws an error: Error: Trying to create an instance of an abstract contract.

I suppose it is due to abstract receiveApproval function specified in standard token: contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }

If I'm right, then how to deploy standard token contract from within another contract?

Update: Code, compiler and error in the browser-solidity: https://ethereum.github.io/browser-solidity/#version=soljson-latest.js&gist=d033d42efe4975df632dff74e889dd05

5 Answers 5


This is an issue with how constructor's inheritance and constructor parameters work.

In your case, MyAdvancedToken inherits from token, and token takes parameters so you need to pass something to it during creation phase.

To fix your code, replace MyAdvancedToken constructor with

/* Initializes contract with initial supply tokens to the creator of the contract */
    function MyAdvancedToken(
        uint256 initialSupply,
        string tokenName,
        uint8 decimalUnits,
        string tokenSymbol,
        address centralMinter
    ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {
        if(centralMinter != 0 ) owner = msg.sender;         // Sets the minter
        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
        decimals = decimalUnits;                            // Amount of decimals for display purposes
        totalSupply = initialSupply;

and it will compile as expected.

I created a simpler example to better show this behavior.

  • Cool. Does this mean that code part in MyAdvancedToken() function that already present in token() function isn't needed after that change? And can I do similar thing for any other function in MyAdvacedToken that is defined in token?
    – Ed Ilyin
    Commented May 28, 2016 at 12:03
  • Right. When a contract inherits another one, it can use all methods of the parent. You can also override parent methods - that is what you actually did - if you want to change the method behavior. If you want to call the actual overridden method and your custom code, you can do something like this: function transfer(address _to, uint256 _value) { super.transfer(address _to, uint256 _value); //add more code here } in your MyAdvancedToken contract. Commented May 28, 2016 at 12:19
  • At solidity.readthedocs.io/en/latest/solidity-in-depth.html and at github.com/ethereum/wiki/wiki/Solidity-Features you can find very extensive documentation about how Solidity works. Commented May 28, 2016 at 12:23

This error is thrown when a contract tries to define abstract and implemented functions together, i.e,

contract foobar {
    function foo();  // will throw error.
    function bar() {}
  • Yeah, mixing abstract and concrete methods is an issue, but this is not the case. Commented May 28, 2016 at 11:35

Successful Deployment With Ethereum Wallet 0.6.2 And 0.7.3 On Linux

I have just tested out the code under the "The Code" section in the page Create your own crypto-currency with Ethereum using Ethereum Wallet (Mist) 0.6.2 on Linux deploying on Testnet.

The contract compiled and deployed successfully. You can find the Testnet contract details at 0xe48f4d015847ca794e2f8769d70acffe92db4f176b8b5ee26c91dfe765cae95d

Note that I have previously synced the Testnet blockchain and used Mist to mine the blockchain to earn some Testnet ethers.

I retested using Ethereum Wallet 0.7.3 on Linux and successfully deployed the contract. You can find the second Testnet contract details at 0x41cefb2cf0709dac540695ac134b05ab0322acfa8443bdd632bdf3c86c4d3c34 .

Unable To Compile In geth

I tried compiling and deploying the contract using geth and could not get it to compile correctly.

I stripped out all the /* ... */ and // comments and removed all the newlines to generate the following statement to be executed in geth:

> var sampleTokenSource='contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }contract MyToken {  string public standard = 'Token 0.1'; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply;  mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance;  event Transfer(address indexed from, address indexed to, uint256 value);  function MyToken( uint256 initialSupply, string tokenName, uint8 decimalUnits, string tokenSymbol ) { balanceOf[msg.sender] = initialSupply;  totalSupply = initialSupply;  name = tokenName;  symbol = tokenSymbol;  decimals = decimalUnits;  }  function transfer(address _to, uint256 _value) { if (balanceOf[msg.sender] < _value) throw;  if (balanceOf[_to] + _value < balanceOf[_to]) throw;  balanceOf[msg.sender] -= _value;  balanceOf[_to] += _value;  Transfer(msg.sender, _to, _value);  }  function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowance[msg.sender][_spender] = _value; tokenRecipient spender = tokenRecipient(_spender); spender.receiveApproval(msg.sender, _value, this, _extraData); return true; }  function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { if (balanceOf[_from] < _value) throw;  if (balanceOf[_to] + _value < balanceOf[_to]) throw;  if (_value > allowance[_from][msg.sender]) throw;  balanceOf[_from] -= _value;  balanceOf[_to] += _value;  allowance[_from][msg.sender] -= _value; Transfer(_from, _to, _value); return true; }  function () { throw;  }}'
(anonymous): Line 1:188 Unexpected identifier (and 1 more errors)

Questions For You

  • What software are you using to compile your contract? What version? What operating system?
  • What are the steps you are performing?
  • I have updated the question with link to code, compiler and error.
    – Ed Ilyin
    Commented May 28, 2016 at 7:58

I posted an answer in this post: Truffle V3.1.9, error running migrations

Short version: You most likely have a function making your contract abstract.


I just ran into this error because I didn't call the base constructor in the child class

contract Child is Parent //inherits from contract "Parent"
    constructor(address _token)
        Parent(_token) //<-if Parent has ctor and left might lead to this error

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.