0

I would like to add the possibility when I mint an NFT to integrate a "URL" in the parameters of the NFT. For this I tried to modify my mint function in my smart contract like this:

@sp.entry_point
def mint(self, params):
        mint_params = sp.TList(
            sp.TRecord(
                to_=sp.TAddress,
                metadata=sp.TMap(sp.TString, sp.TBytes),
                url=sp.TString,
            )
        )
        c = sp.contract(mint_params, self.data.token, entry_point="mint").open_some()
    
        args = [sp.record(
            to_=sp.sender,
            metadata={'': params.metadata},
            url=params.url)]
        sp.transfer(args, sp.mutez(0), c)
    
        
        self.data.data[self.data.token_id] = sp.record(
            holder=sp.sender,
            author=sp.sender,
            amount=params.amount,
            token_id=self.data.token_id,
            collectable=True)
        self.data.token_id += 1

And here is my test:

marketplace.mint(
        amount=sp.tez(100),
        metadata=sp.pack(
            "ipfs://bafyreibwl5hhjgrat5l7cmjlv6ppwghm6ijygpz2xor2r6incfcxnl7y3e/metadata.json"),
        url="https://example.com"
    ).run(sender=admin, valid=False, exception="FA2_NOT_ADMIN")
    token_contract.set_administrator(marketplace.address).run(sender=admin)

Here is the error I receive:

Error: Error in Scenario
Wrong or unsupported exception matching (expected failure in transaction)
Wrong type for contract(0).
(sp.contract(sp.TList(sp.TRecord(metadata = sp.TMap(sp.TString, sp.TBytes), to_ = sp.TAddress, url = sp.TString).layout(("metadata", ("to_", "url")))), self.data.token, entrypoint='mint') : sp.TOption(sp.TContract(sp.TList(
        {
          metadata: sp.TMap(sp.TString, sp.TBytes);
          to_: sp.TAddress;
          url: sp.TString;
        }.layout(("metadata", ("to_", "url")))))))
sp.TList(
  {
    metadata: sp.TMap(sp.TString, sp.TBytes);
    to_: sp.TAddress;
  }.layout(("to_", "metadata")))
instead of
sp.TList(
  {
    metadata: sp.TMap(sp.TString, sp.TBytes);
    to_: sp.TAddress;
    url: sp.TString;
  }.layout(("metadata", ("to_", "url"))))
Please set a stable type.
(__main__, line 35)
Received:'Wrong type for contract'
Expected:'FA2_NOT_ADMIN'
(__main__, line 128)

1 Answer 1

1

The sp.string type cannot contain / and is not suited for URLs.

Instead you can use the sp.bytes type.

That said, the URL should probably be included in the metadata. So I suggest you not to modify your mint entrypoint and include your URL in the metadata.

The bytes value is the hexadecimal encoding equivalent to this in Python:

"0x" + s.encode('utf-8').hex()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.