The API would be far more homogeneous and simplified if the ALGO would be just an asset among others, for example with asset id = 0. It is just a special asset.
For now we need a lot of if
everywhere in our dApp to know if we send ALGO or asset, to use the right function like PaymentTxn
or AssetTransferTxn
, or if we need to use Txn.sender
or Txn.asset_sender
(there are many many examples).
All those useless if
would not be there with a unified API where ALGO is just a special asset.
Here is the kind of helper functions that we are forced to write as dApp developer to be agnostic to the asset sent (“true” asset or ALGO) :
def create_tx(addr_from, addr_to, asset_id, asset_qty):
params = algod_client.suggested_params()
if asset_id == ALGO_ASSET_ID: # ALGO tx
asset_qty = int(round(asset_qty * 1e6)) # API takes amount in microALGOs
tx = algosdk.future.transaction.PaymentTxn(
sender=addr_from, sp=params, receiver=addr_to, amt=asset_qty
)
else:
tx = algosdk.future.transaction.AssetTransferTxn(
sender=addr_from, sp=params, receiver=addr_to,
amt=int(asset_qty), index=asset_id
)
return tx
Or this :
def get_condition_transfer(tx_id, asset_id, amount):
tx = Gtxn[tx_id]
if asset_id == 0: # ALGO transfer
cond = And(
tx.type_enum() == TxnType.Payment,
tx.amount() == Int(amount)
)
else: # asset transfer
cond = And(
tx.type_enum() == TxnType.AssetTransfer,
tx.asset_amount() == Int(amount),
tx.xfer_asset() == Int(asset_id)
)
return cond
I think this should be part of the SDK.