Repository navigation
Expand file tree
/
Copy pathsimple_nft.py
More file actions
125 lines (108 loc) · 3.5 KB
/
Copy pathsimple_nft.py
File metadata and controls
125 lines (108 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright © Supra
# Parts of the project are originally copyright © Aptos Foundation
# SPDX-License-Identifier: Apache-2.0
import asyncio
import json
from examples.common import RPC_NODE_URL, fund_accounts
from supra_sdk.account import Account
from supra_sdk.clients import SupraTokenClient
from supra_sdk.clients.rest import SupraClient
async def main() -> None:
supra_client = SupraClient(RPC_NODE_URL)
token_client = SupraTokenClient(supra_client)
alice = Account.generate()
bob = Account.generate()
collection_name = "Alice's"
token_name = "Alice's first token"
property_version = 0
print(f"Alice account address: {alice.address()}")
print(f"Bob account address: {bob.address()}")
await fund_accounts(supra_client, [alice.address(), bob.address()])
print("\n=== Creating Collection and Token ===")
await token_client.create_collection(
alice, collection_name, "Alice's simple collection", "https://supra.com"
)
await token_client.create_token(
alice,
collection_name,
token_name,
"Alice's simple token",
1,
"https://supra.dev/img/temp.jpeg",
0,
)
collection_data = await token_client.get_collection(
alice.address(), collection_name
)
print(
f"Alice's collection: {json.dumps(collection_data, indent=4, sort_keys=True)}"
)
balance = await token_client.get_token_balance(
alice.address(), alice.address(), collection_name, token_name, property_version
)
print(f"Alice's token balance: {balance}")
token_data = await token_client.get_token_data(
alice.address(), collection_name, token_name
)
print(f"Alice's token data: {json.dumps(token_data, indent=4, sort_keys=True)}")
print("\n=== Transferring the token to Bob ===")
await token_client.offer_token(
alice,
bob.address(),
alice.address(),
collection_name,
token_name,
property_version,
1,
)
await token_client.claim_token(
bob,
alice.address(),
alice.address(),
collection_name,
token_name,
property_version,
)
alice_balance, bob_balance = await asyncio.gather(
token_client.get_token_balance(
alice.address(),
alice.address(),
collection_name,
token_name,
property_version,
),
token_client.get_token_balance(
bob.address(),
alice.address(),
collection_name,
token_name,
property_version,
),
)
print(f"Alice's token balance: {alice_balance}")
print(f"Bob's token balance: {bob_balance}")
print("\n=== Transferring the token back to Alice using MultiAgent ===")
await token_client.direct_transfer_token(
bob, alice, alice.address(), collection_name, token_name, 0, 1
)
alice_balance, bob_balance = await asyncio.gather(
token_client.get_token_balance(
alice.address(),
alice.address(),
collection_name,
token_name,
property_version,
),
token_client.get_token_balance(
bob.address(),
alice.address(),
collection_name,
token_name,
property_version,
),
)
print(f"Alice's token balance: {alice_balance}")
print(f"Bob's token balance: {bob_balance}")
await supra_client.close()
if __name__ == "__main__":
asyncio.run(main())