🥋
Dojo
Inglés
Inglés
  • Dojo
    • 🔎Relevant content
  • App Store
    • Create an Apple Developer Account
    • Create Organizational Account on Apple Developer
    • Upload an App to the App Store
  • Classroom
    • Create a class in Classroom
    • Create and add topics to a Classroom class
    • Add students or teachers in Classroom
    • Assign trainings in Classroom
    • Join a Classroom class as a student
  • Docker
    • Install Docker
  • Git
    • Do a 3-way merge in git
    • Do a Fast Forward merge in git
    • Do a git revert
    • Resolve merge conflicts using the command line
    • Use git add
    • Use git cherry pick
    • Use git rm
    • Use git stash
  • Git Graph
    • Install Git Graph
    • See repository graph
    • Filter branches
    • Merge branch
  • GitBook
    • Create Dojo content in GitBook
    • Create a space in GitBook
    • Delete a space in GitBook
    • Duplicate a space in GitBook
    • Move a space in GitBook
  • GitLab
    • Create a milestone in GitLab
    • View a milestone in GitLab
    • Close a milestone in GitLab
    • Create a repository in GitLab
    • Import issues to GitLab
    • Make a bulk in GitLab
    • Setup two factor authentication for GitLab
    • Create a task in GitLab
    • Viewing tasks in GitLab
    • Close tasks in GitLab
  • Gmail
    • Create a Gmail signature
    • Create an email template in Gmail
    • Send emails with different aliases or groupse
    • Get permissions to send and receive emails from an alias or group
  • HUGO
    • Organize Markdown Content
  • Java
    • Install Java with SDKMan
  • Jira
    • Use shortcuts in jira
    • Use basic filters in jira
    • Use advanced filters in jira
    • Use filters in jira projects
  • Kubernetes
    • Deploy a microservice in Kubernetes
    • See Kubernetes Pod Logs
    • Run a pod with images from a private repository
    • Use config maps to configure a deployment
    • Use secrets to configure a deployment
    • Communicate two microservices in a Kubernetes cluster
    • Create an Ingress Controller on a Cluster
    • Configure Kubernetes Horizontal Pod Autoscaler
    • Connect a container to Google Storage
  • Make
    • Install Make
  • Minikube
    • Install Minikube
    • Manage Cluster With Minikube
    • Use Minikube to Configure a Kubernetes Cluster
  • MySQL
    • Dump a database in MySQL
    • Install MySQL with Docker container
  • Node.js
    • Install Gray-matter
    • Use Gray-matter
    • Read File in Node.js
  • Open SSH
    • Generate SSH private-public key pair
  • Play Store
    • Upload an App to the Google Play Store
    • Create organizational account in Play store
  • Screen Recorder
    • Loom
      • Install Loom
      • Record with Loom
  • Tezos
    • Deploy a smart contract
    • Implement a NFT contract
    • Interact with a smart contract with Taquito
  • Telegram
    • Forward messages to multiple users
  • VaultWarden
    • Create an account
    • How can I create a password?
    • Sharing credentials with external parties
  • Video editor
    • HandBrake
      • Change the format of a video in HandBrake
    • iMovie
      • Edit video in iMovie
  • Visual Studio Code
    • Install visual studio code
    • Install extensions in vscode
  • VueJS
    • Create a project with Vue
    • Install VueCLI
  • YouTube
    • Upload a video to YouTube
  • Zoho
    • Share access from zoho
    • Remove access from zoho
    • Login to the dojo base with a shared access by zoho
Powered by GitBook
On this page
  • Customisation
  • Reference Links
  1. Tezos

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

class ExampleFa2Nft(
    FA2.Admin,
    FA2.ChangeMetadata,
    FA2.WithdrawMutez,
    FA2.OnchainviewBalanceOf,
    FA2.Fa2Nft
):

Init Some mixins need be initialized.

class ExampleFa2Nft(FA2.Admin, FA2.Fa2Nft):
    def __init__(self, admin, metadata):
        FA2.Fa2Nft.__init__(self, metadata)
        FA2.Admin.__init__(self, admin)

Storage

class ExampleFa2Nft(FA2.Admin, FA2.Fa2Nft):
    def __init__(self, admin, metadata):
        FA2.Fa2Nft.__init__(self, metadata)
        FA2.Admin.__init__(self, admin)
        self.update_initial_storage(
            closed = False,
        )

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

 @sp.entry_point
    def mint(self, to_, metadata):
        sp.verify(sp.sender == self.data.administrator, "FA2_NOT_ADMIN")
        token_id = sp.compute(self.data.next_token_id)
        self.data.token_metadata[token_id] = sp.record(
            token_id=token_id, token_info=metadata
        )
        self.data.ledger[token_id] = to_
        self.data.next_token_id += 1

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

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

Or in self contract:

sp.add_compilation_target(
    "Fa2Nft_tokens",
    ExampleFa2Nft(
        metadata_base = {
            "version": "1.0.0",
            "description" : "This implements FA2 (TZIP-012) using SmartPy.",
            "interfaces": ["TZIP-012", "TZIP-016"],
            "authors": ["SmartPy <https://smartpy.io/#contact>"],
            "homepage": "https://smartpy.io/ide?template=FA2.py",
            "source": {
                "tools": ["SmartPy"],
                "location": "https://gitlab.com/SmartPy/smartpy/-/raw/master/python/templates/FA2.py"
            },
            "permissions": {
                "receiver": "owner-no-hook",
                "sender": "owner-no-hook"
            }
        }
    )
)

Reference Links

PreviousDeploy a smart contractNextInteract with a smart contract with Taquito

Last updated 2 years ago

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

You can see more entrypoint examples in .

mixins
Template Minimal
https://opentezos.com/smart-contracts/simple-nft-contract-1/