技术问询:如何使用Python API在Neblio测试网发行代币?
Complete Implementation for Issuing NTP1 Tokens on Neblio Testnet via Python API
Got it, let's wrap up your NTP1 token issuance code for Neblio's testnet. You've got the initial setup right, but we need to fill in missing required fields, handle transaction signing, and broadcast the finalized transaction to the network. Here's the full working implementation:
from __future__ import print_function import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # Configure the API to use Neblio's testnet endpoint swagger_client.configuration.host = "https://testnet.nebl.io" # Create instances of the required API classes ntp1_api = swagger_client.TestnetNTP1Api() transaction_api = swagger_client.TestnetTransactionApi() # Initialize the token issuance request object body = swagger_client.IssueTokenRequest() # -------------------------- # Fill in required token details # -------------------------- # Address issuing the token (your testnet address) body.issue_address = "TUfp4Ss95xaKQPNGpbiZDsMPe4NR16CDiL" # Total supply of the token body.amount = 1000 # Divisibility: 0 = token is non-divisible (whole units only), 8 = like Bitcoin (up to 8 decimals) body.divisibility = 0 # Token symbol (max 8 characters) body.symbol = "MYTST" # Token name (max 32 characters) body.name = "My Test NTP1 Token" # Transaction fee (in satoshis; 10000 is sufficient for testnet) body.fee = 10000 # Optional: Add extra metadata (remove if not needed) body.description = "A test token issued via Neblio's Python API" body.url = "https://example.com/mytoken" try: # Step 1: Build the unsigned token issuance transaction print("Building unsigned transaction...") unsigned_tx = ntp1_api.build_issue_token(body) pprint(unsigned_tx) # Step 2: Sign the transaction with your private key # Replace YOUR_TESTNET_PRIVATE_KEY with the private key for your issue_address private_key = "YOUR_TESTNET_PRIVATE_KEY" signed_tx = transaction_api.sign_transaction(unsigned_tx, private_key) print("\nSigned transaction:") pprint(signed_tx) # Step 3: Broadcast the signed transaction to the testnet print("\nBroadcasting transaction...") broadcast_response = transaction_api.broadcast_transaction(signed_tx) print("Transaction broadcast successful!") pprint(broadcast_response) except ApiException as e: print("Exception when calling API: %s\n" % e)
Key Notes:
- Divisibility: Adjust the
divisibilityvalue based on your token's needs. Use0if you want tokens to only exist as whole units, or a higher number (up to 8) for divisible tokens. - Private Key: You must replace
YOUR_TESTNET_PRIVATE_KEYwith the actual private key associated with theissue_addressyou specified. Never share your private key publicly! - Token Limits: The
symbolcan't exceed 8 characters, andnameis limited to 32 characters. Stick to these limits to avoid API errors. - Fee: The
feevalue of 10000 satoshis is more than enough for testnet transactions. You can adjust it, but keep it above the minimum network fee to ensure the transaction is processed.
Once you run this code successfully, you'll get a transaction ID in the broadcast response. You can verify the token issuance using Neblio's testnet block explorer by searching for this transaction ID.
内容的提问来源于stack exchange,提问作者Kamil Septio Trojnar
相关产品推荐
相关产品推荐

