algorand / py-algorand-sdk

Algorand Python SDK
MIT License
268 stars 143 forks source link

"Asset Transaction Not Supported" when trying to create a new ASA #186

Closed danmurphy1217 closed 3 years ago

danmurphy1217 commented 3 years ago

Hello, I am trying to create a coin on top of the Algorand Blockchain. I generated two new accounts (creator and receiver) and am trying to create the Algorand Standard Asset by running the following code:

def create(passphrase:str= None):
    """
    creates the asset that is defined in `config.py`, signs it, and sends it
    to the algorand network if the senders passphrase is supplied. Otherwise,
    the transaction is written to a file.

    :param passphrase -> ``str``: the user passphrase.
    """
    transaction_data = add_network_params(client, asset_details)
    transaction = AssetConfigTxn(**transaction_data)

    if passphrase:
        transaction_info = sign_and_send(transaction, passphrase, client)
        print(f"Create asset confirmation, transaction ID: {transaction}")
        asset_id = transaction_info['txresults'].get('createdasset')
        print(f"Asset ID: {asset_id}")
    else:
        write_to_file([transaction], "create_coin.txn")

def sign_and_send(transaction: str, passphrase: str, client: algod.AlgodClient) -> Dict[str, str or int]:
    """
    sign and send a transaction to the algorand network. Return the transaction
    info when the transaction is completed.

    :param transaction -> ``AssetTransferTxn``: the transaction object.
    :param passphrase -> ``str``: the public key for the user involved in the transaction.
    :param client -> ``algod.AlgodClient``: an algorand client object.
    """
    private_key = mnemonic.to_private_key(passphrase)
    signed_transaction = transaction.sign(private_key)
    transaction_id = signed_transaction.transaction.get_txid()
    print("IN SIGN AND SEND")
    client.send_transaction(signed_transaction, headers={'content-type': 'application/x-binary'})
    transaction_info = wait_for_confirmation(client, transaction_id)
    return transaction_info

The error occurs during client.send_transaction(), and the full stack trace is this:

Traceback (most recent call last):
  File "/Users/danielmurphy/Desktop/pos-etf/venv/lib/python3.9/site-packages/algosdk/algod.py", line 75, in algod_request
    resp = urlopen(req)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/danielmurphy/Desktop/pos-etf/pos_etf/coin/main.py", line 100, in <module>
    print(create(creator_passphrase))
  File "/Users/danielmurphy/Desktop/pos-etf/pos_etf/coin/main.py", line 64, in create
    transaction_info = sign_and_send(transaction, passphrase, client)
  File "/Users/danielmurphy/Desktop/pos-etf/pos_etf/coin/util.py", line 89, in sign_and_send
    client.send_transaction(signed_transaction, headers={'content-type': 'application/x-binary'})
  File "/Users/danielmurphy/Desktop/pos-etf/venv/lib/python3.9/site-packages/algosdk/algod.py", line 290, in send_transaction
    return self.send_raw_transaction(encoding.msgpack_encode(txn),
  File "/Users/danielmurphy/Desktop/pos-etf/venv/lib/python3.9/site-packages/algosdk/algod.py", line 277, in send_raw_transaction
    return self.algod_request("POST", req, data=txn, headers=tx_headers, **kwargs)["txId"]
  File "/Users/danielmurphy/Desktop/pos-etf/venv/lib/python3.9/site-packages/algosdk/algod.py", line 83, in algod_request
    raise error.AlgodHTTPError(raisex)
algosdk.error.AlgodHTTPError: transaction {_struct:{} Sig:[49 125 119 75 222 209 248 251 225 87 49 76 78 98 100 58 147 223 168 21 61 28 91 230 138 150 117 89 226 56 46 145 241 145 53 253 79 124 51 232 128 181 182 131 191 20 90 203 95 197 24 94 36 41 215 197 212 87 29 62 109 162 74 0] Msig:{_struct:{} Version:0 Threshold:0 Subsigs:[]} Lsig:{_struct:{} Logic:[] Sig:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Msig:{_struct:{} Version:0 Threshold:0 Subsigs:[]} Args:[]} Txn:{_struct:{} Type:acfg Header:{_struct:{} Sender:3J5C253U6UEQS4Q3TCDVWNWHG5WYOM5RYXP7N5YKNTBJW2NMSDICPCIWD4 Fee:{Raw:1000} FirstValid:636047 LastValid:637047 Note:[] GenesisID:testnet-v1.0 GenesisHash:JBR3KGFEWPEE5SAQ6IWU6EEBZMHXD4CZU6WCBXWGF57XBZIJHIRA Group:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Lease:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] RekeyTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} KeyregTxnFields:{_struct:{} VotePK:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] SelectionPK:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] VoteFirst:0 VoteLast:0 VoteKeyDilution:0 Nonparticipation:false} PaymentTxnFields:{_struct:{} Receiver:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ Amount:{Raw:0} CloseRemainderTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} AssetConfigTxnFields:{_struct:{} ConfigAsset:0 AssetParams:{_struct:{} Total:10000000000 Decimals:0 DefaultFrozen:false UnitName:Pos AssetName:PosETF URL: MetadataHash:[227 176 196 66 152 252 28 20 154 251 244 200 153 111 185 36 39 174 65 228 100 155 147 76 164 149 153 27 120 82 184 85] Manager:3J5C253U6UEQS4Q3TCDVWNWHG5WYOM5RYXP7N5YKNTBJW2NMSDICPCIWD4 Reserve:3J5C253U6UEQS4Q3TCDVWNWHG5WYOM5RYXP7N5YKNTBJW2NMSDICPCIWD4 Freeze:3J5C253U6UEQS4Q3TCDVWNWHG5WYOM5RYXP7N5YKNTBJW2NMSDICPCIWD4 Clawback:3J5C253U6UEQS4Q3TCDVWNWHG5WYOM5RYXP7N5YKNTBJW2NMSDICPCIWD4}} AssetTransferTxnFields:{_struct:{} XferAsset:0 AssetAmount:0 AssetSender:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ AssetReceiver:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ AssetCloseTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} AssetFreezeTxnFields:{_struct:{} FreezeAccount:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ FreezeAsset:0 AssetFrozen:false} ApplicationCallTxnFields:{_struct:{} ApplicationID:0 OnCompletion:NoOpOC ApplicationArgs:[] Accounts:[] ForeignApps:[] ForeignAssets:[] LocalStateSchema:{_struct:{} NumUint:0 NumByteSlice:0} GlobalStateSchema:{_struct:{} NumUint:0 NumByteSlice:0} ApprovalProgram:[] ClearStateProgram:[]} CompactCertTxnFields:{_struct:{} CertRound:0 Cert:{_struct:{} SigCommit:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA SignedWeight:0 SigProofs:[] PartProofs:[] Reveals:map[]}}} AuthAddr:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} invalid : asset transaction not supported

It seems like this is an issue between the two addresses (and their permissions/settings) and not within the code itself. I was following along with this tutorial and all of the coin-related code is publically available here. Let me know if there is any other information you need.

jasonpaulos commented 3 years ago

Hi @danmurphy1217, I don't see any issues with your code. The only reason you would get an error of asset transaction not supported would be if the network you are sending your asset creation transaction to does not support assets. Are you using a private network, and if so how did you create it?

danmurphy1217 commented 3 years ago

@jasonpaulos I followed this tutorial pretty closely and wrote a script here that mirrors the tutorial.

The steps I took to run a node on MainNet were:

  1. install the update.sh file, make it executable, and run it
  2. cd into the node directory and run ./goal node start -d $ALGORAND_DATA
  3. check the status of the node to make sure it is up and running

Then, for the TestNet I ran:

  1. cd into the node directory
  2. mkdir testnetdata
  3. cp genesisfiles/testnet/genesis.json testnetdata
  4. ./goal node start -d testnetdata

Is there any way to check if it is running on a private network? cat testnetdata/algod.net is 127.0.0.1:XXXX

jasonpaulos commented 3 years ago

@danmurphy1217 thanks for the info! When you get this issue are you connecting to your TestNet node? Could you let me know the output of goal node status for the node you're using?

danmurphy1217 commented 3 years ago

Yes, I should be connecting to the TestNet node because I am using the testnetdata algod.token and algod.net values when I instantiate the algod.AlgodClient (line 99 in pos_etc/main.py).

The output of goal node status -d testnetdata is:

Last committed block: 636047
Time since last block: 49237.0s
Sync Time: 245.2s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Round for next consensus protocol: 636048
Next consensus protocol supported: true
Last Catchpoint:
Genesis ID: testnet-v1.0
Genesis hash: SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=
jasonpaulos commented 3 years ago

@danmurphy1217 thanks! I believe the issue is because your node has not caught up to the rest of TestNet yet. According to that status, your last committed block is 636047, but as of now TestNet is on block 13015459. Because your node is still working through past transactions, it's actually still using an old protocol version that doesn't support assets yet. You can see this by going to the consensus protocol link for your node and seeing it's still on the first commit for that repo.

Eventually your node will catch up to rest of the network and you should be able to use assets. However this may take a while, so you might want to use fast catch up to accelerate the process. If you do this, your node will get a recent snapshot of TestNet and it will only take a few seconds or minutes for it to collect the remaining blocks.

jasonpaulos commented 3 years ago

I'm going to close this because it's not specific to the Python SDK anymore, but feel free to continue responding here, or open another issue if there's a different problem related to this SDK.

danmurphy1217 commented 3 years ago

thanks so much @jasonpaulos, that did the trick 🙌