0

Imagine I have a contract I have implemented and deployed like this:

pragma solidity ^0.6.0;

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

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

    constructor() ERC721("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;
    }
}

After deploying the contract and people using for sometime, I feel the need to implement an auction system for these tokens...

How would I structure my solidity code to enable these upgrades without losing original data?

1
  • 1
    Well, you're already using OpenZeppelin, so you may as well use their Proxy infrastructure, which allows you to upgrade your contract. There you go. – goodvibration May 7 '20 at 19:50
1

In your example, there is no restriction on who can mint tokens, so tokens are unlikely to have significant value as anyone can mint additional tokens (unless there is value in having low token IDs).

Assuming you already have this deployed, you could look at doing a migration to a V2, where the ability to mint is restricted. This would mean creating a new contract and minting tokens for the existing holders and updating your own dapp, along with services such as OpenSea to use the new version. Your existing version V1 would still exist but you would be advising holders to use V2. As for auction functionality, I would look at using services such as OpenSea or creating a contract to sell your tokens, rather than baking in to your token.

If you haven't already deployed this on mainnet, you could create an upgradeable contract (depending on your use case) using OpenZeppelin Upgrades.


If you have questions on using OpenZeppelin you can ask in the Community Forum: https://forum.openzeppelin.com/

Disclosure: I am the Community Manager at OpenZeppelin

2
  • Thanks Is it not advisable to develop your own auction system? Is there a drawback to having a custom auction system baked into the token? What if it is a customized auction? – srinivas May 11 '20 at 13:00
  • 1
    My preference is to separate concerns. You can create an auction system in a separate contract, and that contract can either hold tokens to sell or have rights to mint tokens. – abcoathup May 12 '20 at 6:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.