How to programmatically deploy a SmartContract that contains imports from OpenZeppelin suite?

Hello.

I want to programmatically deploy auto generated SmartContracts, that are based on OZ-contracts and contains several import-statements to existing base contracts provided by OpenZeppelin.

Lets say something like in the official examples:

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/contracts/drafts/Counters.sol";

contract GameItem is ERC721Full {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721Full("GameItem", "ITM") public {
    }

    function awardItem(address player, string memory tokenURI) public returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

As far as I know, the ethersjs-library needs the final ABI code to deploy a contract by code:

new ethers.ContractFactory(abi, bytecode[ , signer ] )

Otherwise they offer a function fromSolidity:

ethers.ContractFactory.fromSolidity(compilerOutput [ , signer ])

but this does not find any imported contracts.

Can someone help me here? Many thanks in advance!

1 Like