Implement a NFT contract

Import FA2 library

import smartpy as sp
FA2 = sp.io.import_script_from_url("https://smartpy.io/templates/fa2_lib.py")

Compilation target

sp.add_compilation_target(
    "fa2_nft_tokens",
    ExampleFa2Nft(
        metadata = sp.utils.metadata_of_url("http://example.com")
    )
)

Test

@sp.add_test(name="FA2 NFT tokens")
def test():
    sc = sp.test_scenario()
    sc.table_of_contents()
    sc.h2("FA2")
    example_fa2_nft = ExampleFa2Nft(
        metadata = sp.utils.metadata_of_url("https://example.com")
    )
    sc += example_fa2_nft

Now you can run and compile the contract.

Customisation

Mixins The FA2 library provides small classes from which you can inherit separately in order to add additional features. You can see more mixins in the documentation.

Init Some mixins need be initialized.

Storage

Entrypoint Inside the class we can add new entrypoints or reimplement the ones provided by the library.

You can see more entrypoint examples in Template Minimal.

Contract metadata Contains general descriptions of the contract and the offchain-views. This can be in a JSON file stored on IPFS:

Or in self contract:

Last updated