Error while compiling with oz compile

I am following the tutorial at https://docs.openzeppelin.com/sdk/2.5/linking

Am getting this error when i try to use ‘oz compile’

None of the sub-parsers resolved “/home/costech/Project/contracts/SampleToken.sol” into data. Please confirm your configuration.

Here’s what I have done

mkdir Projects
cd Projects
npm init -y
oz init

 npm install @openzeppelin/upgrades@2.5.3

I created a new SampleToken.sol contract using StandaloneERC20.sol from Openzeppelin Ethereum Package and rename to SampleToken

when i run ‘oz compile or oz create’ i get the error. I don’t know which configuration I have got wrong or haven’t set.

1 Like

Hello @costech, welcome to the forum!

Could you share the contents of your contact file? Thanks!

1 Like

Hi @costech,

Welcome to the community forum :wave:

The first part of the linking documentation describes deploying a standalone ERC20.

In a new project directory:

npm init -y 
oz init 
oz link @openzeppelin/contracts-ethereum-package 

Then you can deploy a StandaloneERC20Token to a development network (ganache-cli):

$ oz create
No contracts found to compile.
? Pick a contract to instantiate @openzeppelin/contracts-ethereum-package/StandaloneERC20
? Pick a network development
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1569213382918
All contracts are up to date
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(name: string, symbol: string, decimals: uint8, initialSupply: uint256, initialHolder: address, minters: address[], pausers: address[])
? name (string): MyToken
? symbol (string): TKN
? decimals (uint8): 18
? initialSupply (uint256): 100000000000000000000
? initialHolder (address): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
? minters (address[]): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
? pausers (address[]): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
✓ Setting everything up to create contract instances
✓ Instance created at 0x4bf749ec68270027C5910220CEAB30Cc284c7BA2
0x4bf749ec68270027C5910220CEAB30Cc284c7BA2

You can then interact with the deployed contract using oz call and oz send-tx

$ oz call
? Pick a network development
? Pick an instance StandaloneERC20 at 0x4bf749ec68270027C5910220CEAB30Cc284c7BA2
? Select which function totalSupply()
✓ Method 'totalSupply()' returned: 100000000000000000000
100000000000000000000
$ oz send-tx
? Pick a network development
? Pick an instance StandaloneERC20 at 0x4bf749ec68270027C5910220CEAB30Cc284c7BA2
? Select which function transfer(to: address, value: uint256)
? to (address): 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
? value (uint256): 5000000000000000000
✓ Transaction successful. Transaction hash: 0xe399177b31304813461e0a573b3fe6fe6f85c77282725d020c0e166c9cb70cde
Events emitted:
 - Transfer(0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1, 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0, 5000000000000000000)

I was able to get the same error as you when I tried to compile with an empty contract file. Please check that you had contract code in NewProject.sol

$ oz compile
None of the sub-parsers resolved "/contracts/MyToken.sol" into data. Please confirm your configuration.

To create your own token
Install @openzeppelin/upgrades

$ npm install @openzeppelin/upgrades

Save the following SimpleToken.sol into the contracts directory

SimpleToken.sol

pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol";

/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 */
contract SimpleToken is Initializable, ERC20, ERC20Detailed {
    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    function initialize(address sender) public initializer {
        ERC20Detailed.initialize("SimpleToken", "SIM", 18);

        _mint(sender, 10000 * (10 ** uint256(decimals())));
    }
}

Create the contract (this also compiles the contract) and initialize it

$ oz create
✓ Compiled contracts with solc 0.5.11 (commit.c082d0b4)
? Pick a contract to instantiate SimpleToken
? Pick a network development
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1569213382918
✓ Contract SimpleToken deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(sender: address)
? sender (address): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
✓ Setting everything up to create contract instances
✓ Instance created at 0xFF5181e2210AB92a5c9db93729Bc47332555B9E9
0xFF5181e2210AB92a5c9db93729Bc47332555B9E9

You can then use oz call and oz send-tx to interact with the contract.

$ oz call
? Pick a network development
? Pick an instance SimpleToken at 0xFF5181e2210AB92a5c9db93729Bc47332555B9E9
? Select which function balanceOf(owner: address)
? owner (address): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
✓ Method 'balanceOf(address)' returned: 10000000000000000000000
10000000000000000000000

I was able to resolve this. I didn’t specify the path for imported contracts.

1 Like