Integrating with the Colorverse

colorverse.io
4 min readMay 18, 2021

Technical details on how to get your NFT contract to call and use the Colorverse token contract. Include the Colorverse token owner community in your NFT project.

Solidity Smart Contract integration with the 16,777,216 colors of the Colorverse.

One of the most interesting things about the Colorverse is something that is not immediately obvious: the distribution of Colors across the community of Colorverse token-holders.

The Colorverse gives NFT artists and creative technologists, who design and code their own smart contracts for generative or on-chain art, a very interesting toolbox and a community of people interested in digital art, technology and colors.

Colorverse, Founder Tokens and NFWe are three projects the Colorverse team has created. All three store the artwork on-chain as SVG text strings, so the artwork will be forever retrievable directly from the Ethereum blockchain.

Because of the open and permissionless nature of this project, we want to help creative, digital artists understand how they might create their own 100% on-chain artwork using the Colorverse token contract and the community’s growing distribution of colors and token-holders. This involves understanding SVG images, how Colorverse Token Ids map inherently to the Hex color system, and how to query the Colorverse contract to determine things like: if an address owns a specific color, if the color token exists or translating from the integer token id to the color’s hex string (for use in the construction of an SVG string).

Because each color can only be owned by one address, the artist can guarantee the uniqueness of an SVG-based, on-chain artwork!

(See copyable code at the end.)

In your NFT smart contract, you should first define the interface to the Colorverse. You can choose to use and include and access any of the public functions defined in the Colorverse smart contract (just use “external” instead of “public” in the interface definition):

Defining the interface to the Colorverse contract.

Next, specify the Colorverse’s contract address:

Mainnet Colorverse Contract: 0xfEe27FB71ae3FEEEf2c11f8e02037c42945E87C4R

Rinkeby Testnet Colorverse Contract: 0x0654b88c3B4902CdA9d1E7D7257075D9a2186720

The Colorverse contract is deployed to Mainnet and Rinkeby.

Now figure out how you want to work with and query the Colorverse. Here’s an example of verifying ownership of a specific color:

Querying the Colorverse contract to determine if an address owns a specific Colorverse Token Id.

The next two examples show you how to get the Hex color string if you have a specific Colorverse Token Id. The Hex string is what you will use when you assemble your artworks’ SVG code:

Getting the Hex string (e.g. “#BADA55”) for a specific Colorverse Token Id.
Getting the Hex string for a specific Colorverse Token Id as a re-usable function.

You can also get creative by manipulating or doing operations on a Colorverse Token Id. After all, they are just integer numbers and you can do interesting this with numbers and math ;) Remember, Hex color representations are numbers too, just using a different base. Here is where you can have fun and discover surprising things about the math behind colors and the Hex system:

Be creative! Do transformations on a Colorverse Token Id! Here we calculated the complementary color for the NFWe token.

In our most recent project, NFWe, we used a color of the token-holders choice (their individual, totally unique color palette) to create an NFT with their input. We also calculated the color’s complement on-chain and used that too!

An address becomes a unique, exclusive and customizable color palette for on-chain SVG-based NFT artworks.

To store your artwork on-chain, forever, you can create a string of the SVG which is assembled and returned directly from the Ethereum blockchain. Notice this is a “public view” function that costs nothing to call and get the specific artwork! We think this part is super-cool!

Assembling and returning the SVG-based, on-chain artwork.

By integrating with the Colorverse, you are essentially giving your audience and collectors a color palette, allowing them to contribute to the design and outcome of the artwork:

An address’s individual, exclusive and unique Colorverse Color Palette.

Above all, be creative, make new and exciting art and have fun with the colorverse.io

Copyable code:

interface Colorverse {
function ownerOf(uint256 tokenId) external view returns (address);
function tokenIdToColorHex(uint256 tokenId) external view returns (string memory);}
//Mainnet Colorverse contract address
address public cvContract = 0xfEe27FB71ae3FEEEf2c11f8e02037c42945E87C4;
require(msg.sender == Colorverse(cvContract).ownerOf(_cvTokenId), "Address does not own color");string memory cvColor = Colorverse(cvContract).tokenIdToColorHex(cvTokenId);function getHexForTokenId(uint256 _cvTokenId) internal view returns (string memory) {
return Colorverse(cvContract).tokenIdToColorHex(_cvTokenId);
}
function getComplementHex(uint256 _cvTokenId) internal view returns (string memory) {
return Colorverse(cvContract).tokenIdToColorHex(16777215 - _cvTokenId);
}
string svg1 = "<svg xmlns='http://www.w3.org/2000/svg'><rect width='350' height='350' style='fill: ";
string svg2 = "'><title>";
string svg3 = "</title></rect></svg>";
string svga = "<svg%20xmlns='http://www.w3.org/2000/svg'><rect%20width='350'%20height='350'%20style='fill:%20";
function renderSVG(uint256 tokenId) public view returns (string memory) {
require(_exists(tokenId), "SVG query for nonexistent token");
string memory hx = tokenIdToColorHex(tokenId);
return string(abi.encodePacked(svg1, hx, svg2, hx, svg3));
}

--

--

colorverse.io

All Colors. Tokenized. 1/1. Find your colors. Own your colors. Tokens for on-chain programmable NFT art.