We will be leveraging the Transparency Proxy Pattern (EIP-1967) for our game NFTs.
What is a Proxy
A proxy allows smart contract codes to change and update without compromising the benefits of smart contracts. OpenZepplin has pioneered the way for projects to implement the “unstructured storage” proxy pattern.
In the case of Apollo gaming, it allows us to upgrade our NFT contract as the Apollo gaming ecosystem evolves.
For a long time, the leading thought on Ethereum smart contracts was that they should be immutable. There was no viable way to “update” a contract.
The solution many times was a complicated “migration” process of issuing new tokens to holders and hoping holders are following along with announcements about why they have seemingly duplicate tokens in their wallets. Or holders may even need to pay gas to have the new version of the token issued to them.
But now the creation of “Proxies” have allowed developers to write smart contracts with the ability to publish future updates.
How Proxies Work
The process works by first creating the “proxy contract”. This contract will hold the storage for the token (NFT) and will then be pointed to another implementation contract for its logic. For instance, your token balance information is sitting on the proxy contract. However, if you want to transfer the token, the proxy will look at the implementation contract for how to handle the transfer—then do the writing to the proxy contract’s storage.
Aside from making changes to how transfers work, you can add features. So, an NFT that includes a character name can now be upgraded to include something like a Guild that the NFT belongs to.
Here is a sample use case where a User wants to fetch info about their NFT:
- The user makes some function call to return the values of their NFT.
- The Proxy contract holds storage but is unsure of what to do with it. So it looks to its current implementation contract for how to handle the function call.
- The Implementation contract says that the proxy contract needs to return the Character object that holds a name in V1, but then a name and a guild in V2.
The Proxy contract fetches the name(V1) or name + guild (V2) for that specific NFT and returns it to the user.
OpenZeppelin as a Standard
We are using OpenZeppelin’s transparency proxy library along with Truffle to build our upgradeable contract. OpenZeppelin is the leader in smart contract libraries and Truffle is the go-to tool suite for smart contract developers. This combination allows us to set up automated testing and will be able to tell us if there are any conflicts in storage when doing updates.
EIP-1967 is in use by major groups like Circle with their $USDC token and Lido‘s $stETH token.