Skip to content

Instantly share code, notes, and snippets.

@smondet
Created December 15, 2022 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smondet/284346fb772a13d1d55b7d664c45758a to your computer and use it in GitHub Desktop.
Save smondet/284346fb772a13d1d55b7d664c45758a to your computer and use it in GitHub Desktop.
import smartpy as sp
class FA2_mini(sp.Contract):
def __init__(self, history, metadata):
self.init(
history = history,
metadata = metadata
)
@sp.entry_point
def transfer(self, params):
tx_type = sp.TRecord(to_ = sp.TAddress,
token_id = sp.TNat,
amount = sp.TNat)
tx_type = tx_type.layout(
("to_", ("token_id", "amount"))
)
transfer_type = sp.TRecord(from_ = sp.TAddress,
txs = sp.TList(tx_type)).layout(
("from_", "txs"))
sp.set_type(params, sp.TList(transfer_type))
self.data.history.push(params)
@sp.entry_point
def default(self):
self.data.history = []
def add_test(is_default = True):
@sp.add_test(name = "fa2-mini", is_default = is_default)
def test():
scenario = sp.test_scenario()
scenario.h1("Fake FA2 Contract")
scenario.table_of_contents()
# sp.test_account generates ED25519 key-pairs deterministically:
admin = sp.test_account("Administrator")
alice = sp.test_account("Alice")
bob = sp.test_account("Robert")
# Let's display the accounts:
scenario.h2("Accounts")
scenario.show([admin, alice, bob])
c1 = FA2_mini(history = [], metadata = sp.utils.metadata_of_url("https://example.com"))
scenario += c1
## for the browser version.
if "templates" not in __name__:
add_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment