Skip to content

Commit e685f09

Browse files
committed
feat: NFTTokenCreateTransaction
feat: NFTTokenCreateTransaction feat: NFTTokenCreateTransaction feat: NFTTokenCreateTransaction feat: NFTTokenCreateTransaction feat: NFTTokenCreateTransaction local tests passed fix: supply type enum fix: supply type enum error fix: supply type default as infinite fix: duplicate imports Signed-off-by: exploreriii <[email protected]> chore: Token create type examples Signed-off-by: exploreriii <[email protected]>
1 parent 70de9a5 commit e685f09

File tree

10 files changed

+509
-71
lines changed

10 files changed

+509
-71
lines changed

examples/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ transaction = TokenCreateTransaction(
8585
token_params=TokenParams(
8686
token_name="ExampleToken",
8787
token_symbol="EXT",
88-
decimals=2, # 0 for NON_FUNGIBLE_UNIQUE
89-
initial_supply=1000, # 0 for NON_FUNGIBLE_UNIQUE
88+
decimals=2, # 0 for NON_FUNGIBLE_UNIQUE
89+
initial_supply=1000, # 0 for NON_FUNGIBLE_UNIQUE
9090
token_type=TokenType.FUNGIBLE_COMMON, # or TokenType.NON_FUNGIBLE_UNIQUE
91+
max_supply=1000 # Must be 0 for INFINITE
92+
supply_type=SupplyType.FINITE, # or SupplyType.INFINITE
9193
freeze_default=False,
9294
treasury_account_id=operator_id
9395
),
@@ -108,9 +110,11 @@ transaction = (
108110
TokenCreateTransaction() # no params => uses default placeholders which are next overwritten.
109111
.set_token_name("ExampleToken")
110112
.set_token_symbol("EXT")
111-
.set_decimals(2) # 0 for NON_FUNGIBLE_UNIQUE
112-
.set_initial_supply(1000) # 0 for NON_FUNGIBLE_UNIQUE
113-
.set_token_type(TokenType.FUNGIBLE_COMMON) # or TokenType.NON_FUNGIBLE_UNIQUE
113+
.set_decimals(2) # 0 for NON_FUNGIBLE_UNIQUE
114+
.set_initial_supply(1000) # 0 for NON_FUNGIBLE_UNIQUE
115+
.set_token_type(TokenType.FUNGIBLE_COMMON) # or TokenType.NON_FUNGIBLE_UNIQUE
116+
.set_max_supply(1000) # Must be 0 for INFINITE
117+
.set_supply_type(SupplyType.FINITE) # or SupplyType.INFINITE
114118
.set_freeze_default(False)
115119
.set_treasury_account_id(operator_id)
116120
.set_admin_key(admin_key) # added but optional. Necessary for Token Delete or Update.
@@ -352,7 +356,7 @@ transaction.execute(client)
352356
transaction.execute(client)
353357
```
354358
#### Method Chaining:
355-
```
359+
```
356360
transaction = (
357361
TopicCreateTransaction()
358362
.set_memo("My Super Topic Memo")
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
This is a simple example of how to create a token using setting methods.
2+
This is a simple example of how to create a finite fungible token using setting methods.
33
44
It:
55
1. Loads environment variables.
@@ -25,14 +25,15 @@
2525
PrivateKey,
2626
TokenCreateTransaction,
2727
Network,
28-
TokenType
28+
TokenType,
29+
SupplyType
2930
)
3031

3132
# Load environment variables from .env file
3233
load_dotenv()
3334

34-
def create_token():
35-
"""Function to create a fungible token on the Hedera network."""
35+
def create_token_fungible_finite():
36+
"""Function to create a finite fungible token."""
3637

3738
# Network Setup
3839
network = Network(network='testnet')
@@ -54,35 +55,41 @@ def create_token():
5455
# In this example, we set up a default empty token create transaction, then set the values
5556
transaction = (
5657
TokenCreateTransaction()
57-
.set_token_name("MyToken")
58-
.set_token_symbol("MTK")
59-
.set_decimals(2) # 0 for NON_FUNGIBLE_UNIQUE
60-
.set_initial_supply(10) # 0 for NON_FUNGIBLE_UNIQUE
58+
.set_token_name("FiniteFungibleToken")
59+
.set_token_symbol("FFT")
60+
.set_decimals(2)
61+
.set_initial_supply(10) # TokenType.FUNGIBLE_COMMON must have >0 initial supply. Cannot exceed max supply
6162
.set_treasury_account_id(operator_id) # Also known as treasury account
62-
.set_token_type(TokenType.FUNGIBLE_COMMON) # or TokenType.NON_FUNGIBLE_UNIQUE
63+
.set_token_type(TokenType.FUNGIBLE_COMMON)
64+
.set_supply_type(SupplyType.FINITE)
65+
.set_max_supply(100)
6366
.set_admin_key(admin_key) # Optional
6467
.set_supply_key(supply_key) # Optional
6568
.set_freeze_key(freeze_key) # Optional
6669
.freeze_with(client) # Freeze the transaction. Returns self so we can sign.
67-
.sign(operator_key) # Required signature of treasury account
68-
.sign(admin_key) if admin_key else None # Only sign if admin_key is present. No need to sign with the supply or freeze keys to create the token.
69-
7070
)
7171

72+
# Required signature by treasury (operator)
73+
transaction.sign(operator_key)
74+
75+
# Sign with adminKey if provided
76+
if admin_key:
77+
transaction.sign(admin_key)
78+
7279
try:
7380

7481
# Execute the transaction and get the receipt
7582
receipt = transaction.execute(client)
7683

7784
if receipt and receipt.tokenId:
78-
print(f"Token created with ID: {receipt.tokenId}")
85+
print(f"Finite fungible token created with ID: {receipt.tokenId}")
7986
else:
80-
print("Token creation failed: Token ID not returned in receipt.")
87+
print("Finite fungible token creation failed: Token ID not returned in receipt.")
8188
sys.exit(1)
8289

8390
except Exception as e:
8491
print(f"Token creation failed: {str(e)}")
8592
sys.exit(1)
8693

8794
if __name__ == "__main__":
88-
create_token()
95+
create_token_fungible_finite()
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"""
2+
This is a simple example of how to create an infinite fungible token using setting methods.
3+
4+
It:
5+
1. Loads environment variables.
6+
2. Sets up a client and creates a token with the given parameters.
7+
3. Executes the token creation and prints the result.
8+
9+
Required environment variables:
10+
- OPERATOR_ID, OPERATOR_KEY (mandatory)
11+
- ADMIN_KEY, SUPPLY_KEY, FREEZE_KEY (optional)
12+
13+
Dependencies:
14+
- dotenv
15+
- hiero_sdk_python
16+
"""
17+
18+
# Adapt imports and paths as appropriate
19+
import os
20+
import sys
21+
from dotenv import load_dotenv
22+
from hiero_sdk_python import (
23+
Client,
24+
AccountId,
25+
PrivateKey,
26+
TokenCreateTransaction,
27+
Network,
28+
TokenType,
29+
SupplyType
30+
)
31+
32+
# Load environment variables from .env file
33+
load_dotenv()
34+
35+
def create_token_fungible_infinite():
36+
"""Function to create an infinite fungible token."""
37+
38+
# Network Setup
39+
network = Network(network='testnet')
40+
client = Client(network)
41+
42+
# Operator credentials (must be present)
43+
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
44+
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
45+
46+
# Optional Token Keys
47+
admin_key = PrivateKey.from_string(os.getenv('ADMIN_KEY'))# Optional
48+
supply_key = PrivateKey.from_string(os.getenv('SUPPLY_KEY')) # Optional
49+
freeze_key = PrivateKey.from_string(os.getenv('FREEZE_KEY')) # Optional
50+
51+
# Set the operator for the client
52+
client.set_operator(operator_id, operator_key)
53+
54+
# Create the token creation transaction
55+
# In this example, we set up a default empty token create transaction, then set the values
56+
transaction = (
57+
TokenCreateTransaction()
58+
.set_token_name("InfiniteFungibleToken")
59+
.set_token_symbol("IFT")
60+
.set_decimals(2)
61+
.set_initial_supply(10) # TokenType.FUNGIBLE_COMMON must have >0 initial supply.
62+
.set_treasury_account_id(operator_id) # Also known as treasury account
63+
.set_token_type(TokenType.FUNGIBLE_COMMON)
64+
.set_supply_type(SupplyType.INFINITE)
65+
.set_max_supply(0) # SupplyType.INFINITE would require a max supply of 0
66+
.set_admin_key(admin_key) # Optional
67+
.set_supply_key(supply_key) # Optional
68+
.set_freeze_key(freeze_key) # Optional
69+
.freeze_with(client) # Freeze the transaction. Returns self so we can sign.
70+
)
71+
72+
# Required signature by treasury (operator)
73+
transaction.sign(operator_key)
74+
75+
# Sign with adminKey if provided
76+
if admin_key:
77+
transaction.sign(admin_key)
78+
79+
try:
80+
81+
# Execute the transaction and get the receipt
82+
receipt = transaction.execute(client)
83+
84+
if receipt and receipt.tokenId:
85+
print(f"Infinite fungible token created with ID: {receipt.tokenId}")
86+
else:
87+
print("Infinite fungible token creation failed: Token ID not returned in receipt.")
88+
sys.exit(1)
89+
90+
except Exception as e:
91+
print(f"Token creation failed: {str(e)}")
92+
sys.exit(1)
93+
94+
if __name__ == "__main__":
95+
create_token_fungible_infinite()
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"""
2+
This is a simple example of how to create a finite nft token using setting methods.
3+
4+
It:
5+
1. Loads environment variables.
6+
2. Sets up a client and creates a token with the given parameters.
7+
3. Executes the nft token creation and prints the result.
8+
9+
Required environment variables:
10+
- OPERATOR_ID, OPERATOR_KEY (mandatory)
11+
- ADMIN_KEY, SUPPLY_KEY, FREEZE_KEY (optional)
12+
13+
Dependencies:
14+
- dotenv
15+
- hiero_sdk_python
16+
"""
17+
18+
# Adapt imports and paths as appropriate
19+
import os
20+
import sys
21+
from dotenv import load_dotenv
22+
from hiero_sdk_python import (
23+
Client,
24+
AccountId,
25+
PrivateKey,
26+
TokenCreateTransaction,
27+
Network,
28+
TokenType,
29+
SupplyType
30+
)
31+
32+
# Load environment variables from .env file
33+
load_dotenv()
34+
35+
def create_token_nft():
36+
"""Function to create a finite non-fungible token."""
37+
38+
# Network Setup
39+
network = Network(network='testnet')
40+
client = Client(network)
41+
42+
# Operator credentials (must be present)
43+
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
44+
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
45+
46+
# Optional Token Keys
47+
admin_key = PrivateKey.from_string(os.getenv('ADMIN_KEY'))# Optional
48+
supply_key = PrivateKey.from_string(os.getenv('SUPPLY_KEY')) # Optional
49+
freeze_key = PrivateKey.from_string(os.getenv('FREEZE_KEY')) # Optional
50+
51+
# Set the operator for the client
52+
client.set_operator(operator_id, operator_key)
53+
54+
# Create the token creation transaction
55+
# In this example, we set up a default empty token create transaction, then set the values
56+
transaction = (
57+
TokenCreateTransaction()
58+
.set_token_name("NFTToken")
59+
.set_token_symbol("NFTT")
60+
.set_decimals(0) # Required to be zero for TokenType.NON_FUNGIBLE_UNIQUE
61+
.set_initial_supply(0) # Required to be zero for TokenType.NON_FUNGIBLE_UNIQUE
62+
.set_treasury_account_id(operator_id) # Also known as treasury account
63+
.set_token_type(TokenType.NON_FUNGIBLE_UNIQUE)
64+
.set_supply_type(SupplyType.FINITE)
65+
.set_max_supply(100)
66+
.set_admin_key(admin_key) # Optional
67+
.set_supply_key(supply_key) # Optional
68+
.set_freeze_key(freeze_key) # Optional
69+
.freeze_with(client) # Freeze the transaction. Returns self so we can sign.
70+
)
71+
72+
# Required signature by treasury (operator)
73+
transaction.sign(operator_key)
74+
75+
# Sign with adminKey if provided
76+
if admin_key:
77+
transaction.sign(admin_key)
78+
79+
try:
80+
81+
# Execute the transaction and get the receipt
82+
receipt = transaction.execute(client)
83+
84+
if receipt and receipt.tokenId:
85+
print(f"Non fungible unique token created with ID: {receipt.tokenId}")
86+
else:
87+
print("Non fungible unique token creation failed: Token ID not returned in receipt.")
88+
sys.exit(1)
89+
90+
except Exception as e:
91+
print(f"Token creation failed: {str(e)}")
92+
sys.exit(1)
93+
94+
if __name__ == "__main__":
95+
create_token_nft()

0 commit comments

Comments
 (0)