Skeleton and Rust Architecture
In this article, you'll learn about the basic architecture behind the NFT contract that you'll develop while following this "Zero to Hero" series.
You'll discover the contract's layout and you'll see how the Rust files are structured in order to build a feature-complete smart contract.
You can find the skeleton contract in our GitHub repository
If you are new to Rust and want to dive into smart contract development, our Quick-start guide is a great place to start.
Introduction
This tutorial presents the code skeleton for the NFT smart contract and its file structure.
Once every file and functions have been covered, we will guide you through the process of building the mock-up contract to confirm that your Rust setup works.
File structure
Following a regular Rust project, the file structure for this smart contract has:
nft-contract
├── Cargo.lock
├── Cargo.toml
├── README.md
└── src
├── approval.rs
├── enumeration.rs
├── lib.rs
├── metadata.rs
├── mint.rs
├── nft_core.rs
├── events.rs
└── royalty.rs
- The file
Cargo.tomldefines the code dependencies - The
srcfolder contains all the Rust source files
Source files
Here is a brief description of what each source file is responsible for:
| File | Description |
|---|---|
| approval.rs | Has the functions that controls the access and transfers of non-fungible tokens |
| enumeration.rs | Contains the methods to list NFT tokens and their owners |
| lib.rs | Holds the smart contract initialization functions |
| metadata.rs | Defines the token and metadata structure |
| mint.rs | Contains token minting logic |
| nft_core.rs | Core logic that allows you to transfer NFTs between users. |
| royalty.rs | Contains payout-related functions |
| events.rs | Contains events related structures |
Explore the code in our GitHub repository.
approval.rs
This allows people to approve other accounts to transfer NFTs on their behalf.
This file contains the logic that complies with the standard's approvals management extension. Here is a breakdown of the methods and their functions:
| Method | Description |
|---|---|
| nft_approve | Approves an account ID to transfer a token on your behalf. |
| nft_is_approved | Checks if the input account has access to approve the token ID. |
| nft_revoke | Revokes a specific account from transferring the token on your behalf. |
| nft_revoke_all | Revokes all accounts from transferring the token on your behalf. |
| nft_on_approve | This callback function, initiated during nft_approve, is a cross contract call to an external contract. |
Loading...