Advanced NFT Operations

This section describes individual token operations that are not part of the basic flows. All operations assume the basic NFT has been already set up, as described in NFT basics.

Packs - Preset Distribution

NFT packs can be set up to follow a predetermined distribution. When packs are opened, the contents of each pack will be determined by an entry in this preset distribution, instead of being determined randomly at the time of opening. The exact entry is chosen based on a cyptographic deterministic ‘shuffle’ (so even though the contents of each pack is determined in advance, the exact entry chosen for each pack is not known in advance).

The setup process involves the following steps:

  1. Create a distribution JSON file

A ‘distribution file’ is simply a list of pack contents, containing one entry for each pack (using a particular JSON format). The simplest way to create a distribution file is to set up an NFT Template as a pack with slots, items and weights and then use the Eluvio Authority Services API to generate well formed distributions based on it. You can inspect or modify the file and when ready go to step (2).

Set up a basic NFT Template pack:

  • create an NFT Template and set up its pack slots and items (see: NFT Metadata)
    • set the “Pack Generator” field to preset (the default option is random)
  • create the NFT contract (see: Create and Bind NFT Contract)

Create a distribution file using elv-live-js:

Use elv-live nft_pack_get_dist and specify the content hash of the NFT Template. Run as a Tenant Admins key. This creates two files, named ‘pack_dist*.json’ and ‘pack_spec*.json’ (file name will also contain the content hash).

./elv-live nft_pack_get_dist hq__BAR1J3nxYvQ2Lhj9tmNPxa51NpaYz2V8LbjHVPBHSyeccV9skqfExvvMbMJy4j9e9Fmk2VdYqk

Inspect the ‘pack_dist*.json’ file and manually update it if desired.

  1. Set the distribution JSON object in the NFT Template metadata.

Use elv-live nft_pack_set_dist and specify the same content hash of the NFT Template used to generate the distribution file (above). Run as a Tenant Admins key. This assumes the ‘pack_dist*.json’ file is present with the same name that it was generated by the previous step.

./elv-live nft_pack_set_dist hq__9Hy8sLSJFYjhYr5KwVh5eEZVZnmdZQEkE9iqqeju74zNboMh4NidsnmtbnQBe7BX2PUJbjRPjk

This command updates the NFT Template object - so once completed, you need to update the Eluvio Live tenant object links and publish it before it takes effect. It is not necessary to ‘rebuild’ the NFT Template after this change.

NFT Redeemables

The NFT implementation used with the Eluvio Live platform has a special feature, called ‘redeemables’, that allows an NFT creator to provide one-time offers to their NFT owners (for example venue entry, merchandise, access to unique off-chain offers, …). The ‘redeemable’ can only be redeemed once by the current owner of the token. If the token is sold or transferred, the new owner will not have the ability to redeem that same offer again.

Each NFT contract has up to 256 redeemables.

The process of setting up redeemables consists of the following steps:

  1. Activate the redeemable offer.

Each redeemable offer is identified by its ‘index’, starting at 0. Activation is done one by one

Example using the elv-live-js tools:

export PRIVATE_KEY=0x...
./elv-live nft_add_offer 0x4ada3485494889cc72671af3c23d6202ffa8518f
  1. For each active redeemable, set up its metadata in the NFT Template

Using the fabric browser: navigate to the NFT template object corresponding to this NFT. Open the “Manage” app.

In the “NFT Details” section, locate “Redeemable Offers”. Add metadata for each of the redeemables you have activated, in order.

  • specify the “Name”
  • optionally specify a description, image, release and end dates and style

Save when done.

Temporary: open the “Manage” app again and navigate to the “Form” tab. This will let you edit JSON metadata manually>

  • find the “offer_id” fields for each of the redeemables that you added metadata for
  • set “offer_id”: “0” for the first one, “offer_id”: “1” for the second one, and so on.

Save when done.

  1. Build the NFT

After making changes to the NFT Template object you must rebuild the NFT metadata.

Example using the elv-live-js tool:

./elv-live nft_build  ilib2DMZq6jy1PBexrh6UmEPqMGf21yR  iq__37T4wZpe3CbweK7jSU8JEAbcUvHk
  1. Update tenant and Eluvio Live reference

When done with all the NFT and marketplace changes, you must update your Eluvio Live tenant object and publish the new version to Eluvio Live.

Note you don’t have to do this after each change - it is typically done when all changes to NFTs and marketplaces have been completed.

You will need your tenant ID and the latest hash of your Eluvio Live tenant object.

Example using the elv-live-js tool:

./elv-live tenant_publish_data --update_links iten4TXq2en3qtu3JREnE5tSLRf9zLod hq__42FhWo2oCcBnpCpQcN2N9oc7gbgABQ3Ptvx6NAzQiVcEusWUBWKb6mizFVavkaGMayXi63McaR

Change/Set NFT Token URI

Each token in an NFT contract has a ’token URI’. Common NFTs are set up to use the same ’token URI’ for all tokens, while generative NFTs are set up to use a different, unique ’token URI’ for each token. NFT contracts can of course use any token URIs, as desired by the creator/owner, but in this section we will refer to tokens created using the Eluvio Authority Services convention (NFTs associated with a content fabric NFT Template object).

Token URIs have the following format:

  • Common NFTs
    • main network: https://main.net955305.contentfabric.io/s/main/q/{content_hash}/meta/public/nft
    • demo netowrk: https://demov3.net955210.contentfabric.io/s/demov3/q/{content_hash}/meta/public/nft
  • Generative NFTs
    • main network: https://main.net955305.contentfabric.io/s/main/q/{content_hash}/meta/public/nfts/{token_id}
    • demo netowrk: https://demov3.net955210.contentfabric.io/s/demov3/q/{content_hash}/meta/public/nfts/{token_id}

As the creator/owner of the NFT contract, a tenant can change token URIs of NFTs after they are issued.

If as a creator/owner of the NFT you prefer token URIs to not be changeable, alter the common contract to disable the ‘set uri’ capability

You can change token URIs directly, by either:

(a) invoking the NFT contract method setTokenURI() directly or via proxy (this is a standard EVM call, not documented here)

(b) Using the Eluvio Authority Services API, via the elv-live-js tools.

The elv-live-js tools provide three ways of changing (setting) token URIs. In all cases the process consists of:

  • updating the NFT Template object to reflect the desired changes (for example a common use case is changing the media associated with the NFT or the NFT’s additional media).
  • re-run the elv-live nft_build command
  • update the tenant’s Eluvio Live top object and republish the new version (see ./elv-live tenant_publish_data)

Run as a member of the Tenant Admins group:

export PRIVATE_KEY=0x...

Construct the new token URI carefully, using the content hash of the NFT Template object.

  1. Single token

To change/set the URI of a single token, specify the tenant ID, NFT contract address and the new token URI. For the single token update, use the option --token_id and specify the token ID of the token to be changed.

./elv-live tenant_set_token_uri single iten4TXq2en3qtu3JREnE5tSLRf9zLod 0x4b2e8e711fb223096c3c16d0a9e3d7b835fb5aaa https://demov3.net955210.contentfabric.io/s/demov3/q/hq__MdjLX5axdjMKweWq2fSdfPqeAAJPnX1R1W4WvsvUsNpZ2EMq4n8qffqvsunBwYdoR6sVyPomew/meta/public/nft --token_id 1
  1. All tokens of an NFT contract (non-generative NFTs only)

To change/set token URIs of all tokens of an NFT contract, specify the tenant ID, NFT contract address and the new token URI.

./elv-live tenant_set_token_uri all iten4TXq2en3qtu3JREnE5tSLRf9zLod 0x4b2e8e711fb223096c3c16d0a9e3d7b835fb5aaa https://demov3.net955210.contentfabric.io/s/demov3/q/hq__MdjLX5axdjMKweWq2fSdfPqeAAJPnX1R1W4WvsvUsNpZ2EMq4n8qffqvsunBwYdoR6sVyPomew/meta/public/nft
  1. Batch

This is the most versatile opion, and can be used with both common and generative NFTs. Construct a CSV file containing each new token URI with the following format:

tokenURI,tokenId
https://host-76-74-28-227.contentfabric.io/s/demov3/q/hq__E4PqmoR2raU3eJe93nLPJ8DAuPtJ7jsRnA1MRkwXmifToqqQH9cN6sXkqFpGuHVHepneqYjTTc/meta/public/nfts/128,128
https://host-76-74-28-227.contentfabric.io/s/demov3/q/hq__E4PqmoR2raU3eJe93nLPJ8DAuPtJ7jsRnA1MRkwXmifToqqQH9cN6sXkqFpGuHVHepneqYjTTc/meta/public/nfts/129,129

Then execute the command:

./elv-live tenant_set_token_uri batch iten4TXq2en3qtu3JREnE5tSLRf9zLod 0x4b2e8e711fb223096c3c16d0a9e3d7b835fb5aaa "-" --csv "token.csv"

Note: The token URI specified as a command line argument is ignored, and the example above uses “-”

Set permissions based on NFT ownership

Contract policy

The contract policy for permissioned NFTs is very simple: it just gives full access to an object (the ‘resource’) to any holder of one of the NFTs specified.

Set contract policy on the NFT template object:

../bin/qfab_cli --config ~/.eluvio/cli/config.json content policy contract set iq__3v5vd3K2oRxFagFxMxsmP1NYCUD6  @/Users/serban/ELV/CODE/elv-docs/auth/common_policies/nft_owner_minter.yaml

Notes: The minter address has to be specified in the policy YAML (this is so the minter can access the template)