FA2 Fellowship | Session 2 : Intro to SmartPy

If you have spent any time exploring the world of NFTs, you have probably heard of smart contracts. They form the backbone of the art ecosystem on Tezos.

The Tezos Foundation and the Museum of the Moving Image launched the FA2 Fellowship as part of their 2025-2026 Partnership, with the aim of empowering artists and builders to learn from industry experts about the Tezos blockchain smart contract applications and develop their own projects.

The second Fellowship session was led by Mathias Hiron, Developer Advocate at Nomadic Labs, covering technical capabilities of smart contracts and hands-on examples of SmartPy. Rather than presenting a rigid set of smart contract rules, he invites an exploration of creative possibilities they unlock to artists and creators.

 

1. What is a Smart Contract?

At its core, a smart contract is a program on a blockchain with four specific technical characteristics:

  1. Immutability: The code cannot be modified once deployed, although the data it relies upon (storage) may change.

  2. Eternity: The contract remains accessible and operational as long as the blockchain is maintained.

  3. Decentralization: Its existence and execution do not rely on any single centralized provider or third party.

  4. Public: Anyone can read its code and storage.

In the Tezos ecosystem, a smart contract is formally classified as an originated account. It is designated by an address beginning with KT, distinguishing it from an implicit account (also user account), which is prefixed with tz. Its unique technical role is defined by its dedicated, mutable storage and executable Michelson code, which dictates its logic and is invoked via entrypoints.

 

2. Capabilities and Limitations

When triggered by a call, a smart contract may perform verifications and computations (including cryptographic functions) and modify the content of its own storage. It can also generate internal operations, which include sending tez to users, calling other smart contracts, creating (originating) new contracts, delegating its balance, or emitting events.

A smart contract is strictly passive; it cannot execute any logic unless it is explicitly called. It operates with full transparency, meaning it cannot perform actions in secret or behave unpredictably. Furthermore, it is isolated from the off-chain world; it cannot access internet data or the transaction history, nor can it directly read the storage of other contracts unless that data is passed as a parameter during the call.

 

3. Storage and Cost

On Tezos, writing data to the blockchain incurs a cost. Imagine a smart contract that permits users to append a text message to a string stored within the contract’s storage.

Costs are proportional to resource usage. Callers must pay 0.00025 tez for each byte of data added to storage. Although it is theoretically possible to store very large strings, the gas required to process such data effectively imposes an upper limit.

When large volumes of data must be stored a simple list or string is not appropriate. In such cases, a big map is used, as it supports an unbounded number of entries without incurring the same gas limitations.

To prevent users from writing anything to the smart contract, you can set strict rules. For instance, you could require every message to be between 3 and 30 characters long. If a user sends a message with more than 30 characters, the smart contract rejects it, cancelling the entire transaction and preserving the blockchain’s state.

Example

 

4. Basic NFT Smart Contract

Non-fungible token (NFT) is defined at a minimum by three elements: uniqueness, an identifiable owner, and associated metadata.

A Basic NFT contract in SmartPy would include:

  • Owner: An address (e.g., tz1...).

  • Metadata: Information describing the asset.

To make it functional, add a give entrypoint to transfer ownership. Crucially, this entrypoint includes a verification: assert sp.sender == self.data.owner. This one line of code ensures that only the current owner can initiate a transfer. Without it, anyone could transfer an NFT.

Example

 

5. Hashing

Typically, an accompanying file associated with an NFT is not stored directly on the blockchain because on-chain storage is costly, as discussed above. Instead of uploading a 4MB image on-chain, the data is verified using Cryptographic Hash, a unique fingerprint of the data.

  • It is deterministic: the same file always produces the same hash.

  • It is small: saving storage costs.

  • It is sensitive: change one pixel in the image, and the hash changes completely.

The smart contract stores only the cryptographic hash of the file, while the image itself is stored off-chain, for example on IPFS.

Example

 

6. Sales and Royalties

Smart contracts become particularly powerful when they combine transactional logic with value transfer. 

An NFT contract can be extended to include a fixed price. A dedicated buy entrypoint that verifies whether the amount of tez sent with the transaction (sp.amount) matches the stored price. If the condition is satisfied, the contract accepts the payment, transfers ownership of the token to the buyer, and forwards the proceeds to the previous owner. 

Also dynamic pricing mechanisms can be implemented, such as automatically increasing the sale price by a fixed percentage (e.g. 10%) after each transaction. The smart contract may further be programmed to split incoming payments—allocating 5% of each sale to the original artist and distributing the remainder to the seller. 

The logic can be further refined to support more sophisticated primary and secondary market models.

Example

 

7. Your Rules and Workarounds

Above mentioned smart contract ideas provide the essential foundation for architecting sophisticated smart contracts. While syntax and logic establish the rules of the code, they do not limit the scope of one’s creative potential.

Imagine a scenario where a smart contract defines that an NFT can only be transferred during a specific one-hour window each day. At first glance, this appears to be a rigid mechanic that fundamentally limits the collection’s liquidity and behavior. However, one can bypass this limitation by creating a separate wrapper contract. This wrapper buys and holds this NFT; while the original asset remains subject to its time-based rules within the vault, the wrapper itself can be transferred at any time.

To ground this abstract concept, imagine a physical-world analogy involving a painting. If a legal contract states that a specific painting is owned by a company and cannot be sold to anyone else other than this company, the asset is effectively locked. But the painting does not need to change the owner—one can simply purchase the company itself. By acquiring the company one gains full control over the asset without ever triggering the technical restrictions of the original sales contract.

Example

Designing a network of smart contracts with layered rule sets that form a living blockchain ecosystem typically encourages the collectors to discover creative workarounds and hidden features embedded in smart contracts as they acquire tokens. Such gamification transforms simple ownership into an engaging challenge, fostering sustained community interaction and long-term activity within the project. This is just one example, there are many other approaches that can enable artists to play creatively with smart contracts on Tezos. 


8. Bugs and Audits

In conventional software applications, bugs can typically be corrected through updates. In contrast, errors in a deployed smart contract often have irreversible consequences that cannot be rectified. This risk underscores the necessity of rigorous testing, formal verification where appropriate, and thorough professional security audits prior to deployment on a mainnet.

While a contract may function correctly in isolation, failing to adhere to established standards (FA2 on Tezos) can significantly limit its usefulness. Contracts that do not follow widely adopted specifications are often incompatible with standard wallets and cannot be indexed or listed by major marketplaces. Interoperability within a blockchain ecosystem depends on collective adherence to common standards, which enable tools, platforms, and users to interact seamlessly with one another.

 

Ready to build? If you want to move from reading to coding:

  1. Go to beta.opentezos.com.

  2. Create an account.

  3. Join the "FA2 Fellowship" with code: k77xmpxth7.

  4. Start SmartPy Course.



Join the next FA2 Fellowship session here

Previous
Previous

FA2 Fellowship | Session 3: FA2 Contracts

Next
Next

FA2 Fellowship| Session 1 : Intro to Blockchain