Examples โ
NFT โ
Simplest NFT โ
python
import smartpy as sp
FA2 = sp.io.import_script_from_url("https://legacy.smartpy.io/templates/fa2_lib.py")
@sp.add_test(name="Simplest NFT")
def test():
sc = sp.test_scenario()
c1 = FA2.Fa2Nft(
metadata = sp.utils.metadata_of_url("https://example.com"),
)
sc += c1
With admin and mint โ
python
import smartpy as sp
FA2 = sp.io.import_script_from_url("https://legacy.smartpy.io/templates/fa2_lib.py")
class NftWithAdmin(FA2.Admin, FA2.MintNft, FA2.Fa2Nft):
def __init__(self, admin, **kwargs):
FA2.Fa2Nft.__init__(self, **kwargs)
FA2.Admin.__init__(self, admin)
@sp.add_test(name="NFT with admin and mint")
def test():
sc = sp.test_scenario()
c1 = NftWithAdmin(
admin = sp.test_account("admin").address,
metadata = sp.utils.metadata_of_url("https://example.com"),
)
sc += c1
Pre-minted โ
Fungible โ
Simplest fungible โ
With admin and mint โ
python
import smartpy as sp
FA2 = sp.io.import_script_from_url("https://legacy.smartpy.io/templates/fa2_lib.py")
class FungibleWithAdmin(FA2.Admin, FA2.MintFungible, FA2.Fa2Fungible):
def __init__(self, admin, **kwargs):
FA2.Fa2Fungible.__init__(self, **kwargs)
FA2.Admin.__init__(self, admin)
@sp.add_test(name="Fungible with admin and mint")
def test():
sc = sp.test_scenario()
c1 = FungibleWithAdmin(
admin = sp.test_account("admin").address,
metadata = sp.utils.metadata_of_url("https://example.com"),
)
sc += c1
Pre-minted fungible tokens โ
In this example we create a FA2 for fungible tokens without mint entrypoint nor admin. All tokens are pre-minted at origination time and given to Alice.
python
import smartpy as sp
FA2 = sp.io.import_script_from_url("https://legacy.smartpy.io/templates/fa2_lib.py")
alice = sp.test_account("Alice")
token_md = make_metadata(name="My Token", decimals=1, symbol="Tok")
@sp.add_test(name="Pre-minted FA2 fungible tokens")
def test():
sc = sp.test_scenario()
# `metadata_base["permissions"]["operator"]` is added by `FA2.Fa2Fungible`.
example_fa2_fungible = FA2.Fa2Fungible(
metadata = sp.utils.metadata_of_url("https://example.com"),
metadata_base = {
"version": "1.0.0",
"description" : "An example token built using SmartPy.",
"interfaces": ["TZIP-012", "TZIP-016"],
"authors": ["SmartPy <https://legacy.smartpy.io/#contact>"],
"homepage": "https://legacy.smartpy.io/docs/guides/FA/FA2/examples",
"source": {
"tools": ["SmartPy"],
"location": "https://legacy.smartpy.io/docs/guides/FA/FA2/example"
},
"permissions": {
"receiver": "owner-no-hook",
"sender": "owner-no-hook"
}
}
token_metadata=[token_md],
ledger={(alice.address, 0): 100_000}
)
sc += example_fa2_fungible