Create your own coin in Algorand

Intro

I was checking Algorand recently, found it is very exciting: Fast transaction speed (< 5s), super cheap transaction fee ($0.001 ~ 0.002), staking has 6% APY, support smart contract and most importantly, it has a healty dev community, provides SDK for many popular languages, like Java, Go, Javascript, Python (heard Rust is also under development), it even has a flutter package.

Algorand provides method to create your own coin, called ASA, like ERC-20 coin in Etherum. I am trying to create one coin with Python and document the steps below.

Steps

1, Create Account

create an account in PureStake to use its API. We can host our local server though, the easiest method is using some web API (those website will host the testnet for you), all we need to do is using some SDK to run the code. Once you create an account in PureStake’s developer portal, you will get the API key, save it somewhere, we will need that in the following steps.

2, Install python SDK:

1
$ pip install py-algorand-sdk

3, Now write our Python code.

The basic flow is:

  1. Create an account
  2. Dispense some tokens to this account with TestNet Dispenser
  3. Use this account to create a “CreateAssetTransaction”
  4. Use this account to sign this transaction
  5. Send this transaction to TestNet/MainNet.

Let’s do it one by one, first create account. Here we write a Python script to create account:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env python

from algosdk import account, mnemonic


def create_account():
private_key, public_addr = account.generate_account()
mn = mnemonic.from_private_key(private_key)
print(f"Public Address: {public_addr}\nMnemonic: {mn}")


if __name__ == "__main__":
create_account()

Run it to generate the account:

1
2
3
$ python create_account.py
Public Address: 73XNVFL4MFBBKRAMJZSXOXU5E5XT3EIFYNYDUAHIHB4Q252ZIV6GAAIYVU
Mnemonic: <Your Mnemonic Passphrase>

4, Put $ALGO in the address

Go to TestNet dispenser to put some tokens into that public address, this will put 100 $ALGO to it.

5, For the rest steps we create another python script to do it:

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
#!/usr/bin/env python

from algosdk.v2client import algod
from algosdk import mnemonic, transaction


ALGOD_ENDPOINT = "https://testnet-algorand.api.purestake.io/ps2"
ALGOD_TOKEN = "cK4H1j6j6Z7q0JTxtsuQR4b3OvJ5MzRV1y1bpMdn"


def create_coin():
mn = input("Your mnemonic words:\n")
public_addr = mnemonic.to_public_key(mn)
private_key = mnemonic.to_private_key(mn)

headers = {
"X-API-Key": ALGOD_TOKEN,
}
# create algod client
client = algod.AlgodClient(
algod_token="",
algod_address=ALGOD_ENDPOINT,
headers=headers,
)

# generate common parameters
params = client.suggested_params()

# create this transaction
txn = transaction.AssetConfigTxn(
sender=public_addr,
fee=params.fee,
first=params.first,
last=params.last,
gh=params.gh,
total=10000000,
default_frozen=False,
unit_name="boron",
asset_name="BoronCoin",
manager=public_addr,
reserve=public_addr,
freeze=public_addr,
clawback=public_addr,
url="https://github.com/bofeng",
decimals=0,
)

# sign the transaction
signed_txn = txn.sign(private_key)

# send the transaction
txid = client.send_transaction(signed_txn)
print(f"Transaction ID: {txid}")


if __name__ == "__main__":
create_coin()

Now let’s run it to create coin:

1
2
3
4
$ python create_coin.py
Your mnemonic words:
<Paste Your Mnemonic Passphrase Here, Hit Enter>
Transaction ID: UZ5Y3SLUKBEWK5GNZ3QLTW63FXV4WWRIMIB54R3MEGSE37GHXR7A

Ok, we got the returned Transaction ID, now use that ID to search the asset info in the TestNet Explorer. Put the transaction ID in the input box, we will see our asset info:

Reference