This C# program is designed to retrieve Ethereum-based Non-Fungible Tokens (NFTs) and calculate the average color of the images associated with these NFTs. It leverages the Ethereum blockchain and external image processing libraries to accomplish this task. The library is using Image Sharp for image analysis and Nethereum for Blockchain interaction via Infura.
IMPORTANT: An Infura API key is required. Infuras free API tier allows for 100,000 free requests a day.
- Connects to the Ethereum blockchain to fetch NFTs using the Ethereum NFT standard (e.g., ERC-721 or ERC-1155).
- Downloads images associated with each NFT.
- Calculates the average color of the images.
- Provides options for specifying the NFT contract address, token IDs, and output format.
Before running the program, ensure you have the following dependencies and prerequisites:
- .NET Core installed on your system.
- Access to an Ethereum node or a service like Infura to interact with the Ethereum blockchain.
- Any additional libraries or packages specified in the project's
csprojfile.
-
Instantiate the EthereumMetadataService
EthereumMetadataService ethereumMetadataService = new EthereumMetadataService("your infura API key");
-
Get NFT Image
//the method takes the contract address and the token id as the parameter byte[] picture = ethereumMetadataService.GetNftPicture("contract address", 1);
-
Optionally you also have the options to get the NFT picture url, metadata url or metadata
//the method takes the contract address and the token id as the parameter string nftPictureUrl = ethereumMetadataService.GetNftPictureUrl("contract address", 1); //the method takes the contract address and the token id as the parameter string nftMetadataUrl = ethereumMetadataService.GetNftMetadataUrl("contract address", 1); //the method takes the contract address and the token id as the parameter string metadata = ethereumMetadataService.GetNftMetadataString("contract address", 1);
-
Instantiate the PixelAverageService
PixelAverageService pixelAverageService = new PixelAverageService();
-
Call the GetTopPixelColor method
//the file is a byte[], the second argument is the amount of colors that is returned, the method returns the RGBA string[] topColors = pixelAverageService.GetTopPixelColor(file, 3);