nft-server

Crates.ionft-server
lib.rsnft-server
version0.1.1
sourcesrc
created_at2022-09-22 19:04:16.355341
updated_at2022-09-23 18:56:30.43111
descriptionA simple, minimal NFT metadata generation trait, and a batteries-included metadata server
homepage
repositoryhttps://github.com/nomad-xyz/nft-server
max_upload_size
id671946
size85,257
James Prestwich (prestwich)

documentation

README

NFT Server

Simple rust lib for NFT Metadata, and a basic axum server for delivering it

$ cargo build
$ cargo clippy
$ cargo run --bin example

Usage

Implement a MetadataGenerator that asynchronously maps a token ID to token metadata, then call serve to serve it. See bin/example.rs as well as the crate::generators::disk::LocalJson generator

Consuming crates need to depend on the following:

  • async_trait
  • url (for convenience, the Url struct is re-exported)
  • ethers (for convenience the U256 struct is re-rexported)

Built-in server

The axum feature (on by default) adds a minimal axum server preconfigured to serve token metadata.

After instantiating your metadata generator, you can serve it over http as follows:

use nft_server::prelude::*;

async main() {
    let my_generator = ...;
    let addr = ([0, 0, 0, 0], 8080);
    serve_generator(my_generator, addr).await;
}

This server has the following routes:

  • /healthcheck - returns 200
  • / - calls MetadataGenerator::contract_metadata() and returns the result
  • /:token_id - as a decimal number. Calls MetadataGenerator::metadata_for(token_id) and returns the result

e.g. localhost:8080/0 will return json metadata for token 0

Commit count: 15

cargo fmt