Create a Custom Token on Stellar Network in Python
Posted By : Jatin Gupta | 31-Dec-2019
This blog is comprised of four python scripts which will help you to create a token on
The steps will be,
1. Host a stellar
2. Create 2
3.
4. Send the token to another address.
I) To create a custom
stellar network,
docker run --rm -it -p "8000:8000" -v "/stellar:/opt/stellar" --name stellar stellar/quickstart --
II)
from stellar_base.keypair import Keypair
def gen_address():
kp = Keypair.random()
publickey = kp.address().decode()
seed = kp.seed().decode()
return publickey, seed
if __name__ == '__main__':
address, password = gen_address()
print(address, password)
This will give you
Example output : GBT6XB6Q7PTUSVR5YESFNTSAQVCSATXF6WISFIK4BZ57MDABYDSMUYS3, SCAZIRCS3QAXRP3HV7Z3JO7X3BCKNEEMDBGHV5PIXZC3CECUGY7IMFCP
Add this address in the below program and fund 10000
import requests
def fund_account(address):
r = requests.get('https://horizon-testnet.stellar.org/friendbot?addr=' + address)
return r.text
if __name__ == '__main__':
ISSUER_ADDRESS = 'GBT6XB6Q7PTUSVR5YESFNTSAQVCSATXF6WISFIK4BZ57MDABYDSMUYS3'
ISSUER_SEED = 'SCAZIRCS3QAXRP3HV7Z3JO7X3BCKNEEMDBGHV5PIXZC3CECUGY7IMFCP'
result = fund_account(ISSUER_ADDRESS)
print(result)
Check the balance in the address using the command
curl http://192.168.9.69:8000/accounts/GBT6XB6Q7PTUSVR5YESFNTSAQVCSATXF6WISFIK4BZ57MDABYDSMUYS3
Now repeat the process again to create a new address and add 10000 XLM.
Once the address
from stellar_base.asset import Asset
def create_asset(code, issuer_address):
asset = Asset(code, issuer_address)
return asset
if __name__ == '__main__':
ISSUER_ADDRESS = 'GBT6XB6Q7PTUSVR5YESFNTSAQVCSATXF6WISFIK4BZ57MDABYDSMUYS3'
ISSUER_SEED = 'SCAZIRCS3QAXRP3HV7Z3JO7X3BCKNEEMDBGHV5PIXZC3CECUGY7IMFCP'
ASSET_CODE = 'token_name'
new_asset = create_asset(ASSET_CODE,ISSUER_ADDRESS)
print(new_asset)
Now we have to issue this asset (token) on the stellar network
from stellar_base.keypair import Keypair
from stellar_base.asset import Asset
from stellar_base.builder import Builder
issuing_secret = 'SCAZIRCS3QAXRP3HV7Z3JO7X3BCKNEEMDBGHV5PIXZC3CECUGY7IMFCP'
issuing_public = Keypair.from_seed(issuing_secret).address().decode()
receiving_secret = 'SCAZIRCS3QAXRP3HV7Z3JO7X3BCKNEEMDBDHACHBQANWKCEHGFQAKQW'
receiving_public = Keypair.from_seed(receiving_secret).address().decode()
my_asset = Asset('token_name', issuing_public)
builder = Builder(
receiving_secret,horizon_uri='http://localhost:8000', network='TESTNET').append_trust_op(
destination=my_asset.issuer, code=my_asset.code)
builder.sign()
resp = builder.submit()
print(resp)
builder = Builder(
issuing_secret,horizon_uri='http://localhost:8000', network='TESTNET').append_payment_op(
destination=receiving_public,
amount='10000',
asset_code=my_asset.code,
asset_issuer=my_asset.issuer)
builder.sign()
resp = builder.submit()
print(resp)
This will issue the token on
Do you want a web app that performs fast and has an interactive user interface? Python is the number one programming language to date. It supports the development of feature-rich apps including video streaming apps, 3D web apps, data science apps and more. Oodles Technologies is a Python development company with more than 10 years of experience. Contact our expert for more details!
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Jatin Gupta
Jatin is a DevOps trainee. He ha deep interest in python and cloud technologies. He likes to read about science/history and fiction, listening to music and explore new places.