nftstorage / nft.storage

**Notice: Uploads Decommissioned - Existing Data is Safe!** NFT.Storage Classic (classic.nft.storage) offers free decentralized storage and bandwidth for NFTs on IPFS and Filecoin. June 2024 Update: No new uploads, but all existing data is safe. Try the new NFT.Storage, which preserves data in long term Filecoin storage. Go to app.nft.storage
https://classic.nft.storage
Other
619 stars 167 forks source link

Support for Token types other than ERC-1155 #1143

Closed 852Kerfunkle closed 5 months ago

852Kerfunkle commented 2 years ago

Would be nice to have. Currently working around the validation by overloading some functions and providing my own.

Could be an option in the interface.

For example, TZIP-12, a token standard on: Tezos https://tzip.tezosagora.org/proposal/tzip-12/#token-metadata

As trival as it is, here's the code:

const validateTZip12 = ({ name, description, decimals }: { name: string, description: string, decimals: number}) => {
    // Just validate that expected fields are present
    if (typeof name !== 'string') {
      throw new TypeError(
        'string property `name` identifying the asset is required'
      )
    }
    if (typeof description !== 'string') {
      throw new TypeError(
        'string property `description` describing asset is required'
      )
    }
    if (typeof decimals !== 'undefined' && typeof decimals !== 'number') {
      throw new TypeError('property `decimals` must be an integer value and ')
    }
}
dchoi27 commented 2 years ago

Hey there! Are you looking for support with the store() function? We were hoping that with the storeBlob and storeCar methods for uploading generic content, folks could hand-roll creating their own metadata if it's not ERC-1155, but it's true that you have to write your own validation of the metadata. Just want to make sure I'm understanding your request!

852Kerfunkle commented 2 years ago

Hello! Yes, with the store() function.

Here's what I'm doing to be able to use the store function, I liked the store function.

// extend NFTStorage to allow us to supply our own validation while keeping
// the simplicity of the store() function.
class NFTStorageTZip extends NFTStorage {
    static override async encodeNFT(input: any) {
        validateTZip12(input)

        return Token.Token.encode(input)
    }

    static override async store(service: Service, metadata: any) {
        const { token, car } = await NFTStorageTZip.encodeNFT(metadata)
        await NFTStorageTZip.storeCar(service, car)
        return token
    }

    override store(token: any) {
        return NFTStorageTZip.store(this, token)
    }

    static override async storeBlob(service: Service, blob: Blob) {
        const { cid, car } = await NFTStorageTZip.encodeBlob(blob)
        await NFTStorageTZip.storeCar(service, car)
        return cid.toString()
    }
}

I'm perfectly happy to keep using it this way, it would just be nice to be able to supply my validation function to NFTStorage.

edit: in terms of not having to make sure this code keeps working as intended.

dchoi27 commented 2 years ago

Makes sense! I think we probably won't give support to many different contract standards for the store() method unless there's a ton of demand for supporting certain standards in store() specifically (given that it's pretty simple to use the other methods to store what metadata you need to!). I think it's a cool idea so will keep the ticket open, but just being transparent that at the moment we probably won't be able to get to it unless we hear more from folks!

852Kerfunkle commented 2 years ago

No worries, thank you for the feedback!