Code Monkey home page Code Monkey logo

Comments (5)

emishur avatar emishur commented on September 25, 2024 1

It's unclear how you mint two different singular NFTs on the same contract with different metadata ...
Everything is catered toward a range of NFT IDs with the same metadata.

Yes, this is a special NFT contract which represents "semi-fungible" NFTs.
You might want to look at NFT collectibles example: https://github.com/oxheadalpha/smart-contracts/tree/master/collectibles
https://github.com/oxheadalpha/smart-contracts/blob/master/collectibles/ligo/src/fa2_single_asset.mligo contract can be originated with a fixed NFT collection where each NFT has different metadata.

You may also have a look at https://github.com/tqtezos/minter-sdk which has a variety of fungible and non-fungible token contracts implementation or take the NFT contract from https://github.com/oxheadalpha/nft-tutorial

from smart-contracts.

johnnyshankman avatar johnnyshankman commented on September 25, 2024

Although I can't manage to write a working lambda, I've managed to assert from this:

(** Finds a definition of the token type (token_id range) associated with the provided token id *)
let find_token_def (tid, token_defs : token_id * (token_def set)) : token_def =
  let tdef = Set.fold (fun (res, d : (token_def option) * token_def) ->
    match res with
    | Some r -> res
    | None ->
      if tid >= d.from_ && tid < d.to_
      then  Some d
      else (None : token_def option)
  ) token_defs (None : token_def option)
  in
  match tdef with
  | None -> (failwith fa2_token_undefined : token_def)
  | Some d -> d

That it seems to match on tid being greater than or equal to the from, but less than the to (exclusive).

So if I want data for token 3 and there are four pairs in storage

Pair(1, 2) -> url1
Pair(2, 3) -> url2
Pair(3, 4) -> url3
Pair(4, 5) -> url4

It will always pick Pair(3,4) with url3 as

3 >= 3 is true
3 < 4  is true

And

3 >= 2 is true
3 < 3  is false

And

3 >= 4 is false
3 < 5  is true

And

3 >= 1 is true
3 < 2  is false

from smart-contracts.

johnnyshankman avatar johnnyshankman commented on September 25, 2024

I think we should put this more clearly somewhere as an example for future devs as it's a pretty odd pattern for something where each token inherently is supposed to have unique data.

I still have no idea how to pass in the lambda for getting token data.

from smart-contracts.

emishur avatar emishur commented on September 25, 2024

The token_metadata endpoint is also a little arcane, as it asks for a lambda as the first parameter and I'm not sure what sort of function it expects.

I still have no idea how to pass in the lambda for getting token data.

This is a special way to implement contract view entry points. Tezos will have Solidity-like view entry points with the next protocol update. At the moment, view entry points use continuation passing style pattern when the parameter contains a callback lambda.

If the contract A wants to get some value from the contract B, it should call contract's A view entry point passing parameters (like token_id) and a callback. Contract B then will call a provided callback entry point of the contract A, passing the requested value.

In general, view entry points cannot be called off-chain (only by other contracts). But Taquito library has special API which lets to inspect view entry points off-chain: https://tezostaquito.io/docs/lambda_view/

from smart-contracts.

johnnyshankman avatar johnnyshankman commented on September 25, 2024

@emishur thank you so much for all of this information. really appreciated

from smart-contracts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.