Algorand Standard Assets (ASAs)
The Algorand protocol supports the creation of on-chain assets that benefit from the same security, compatibility, speed and ease of use as the Algo. The official name for assets on Algorand is Algorand Standard Assets (ASA).
With Algorand Standard Assets you can represent stablecoins, loyalty points, system credits, and in-game points, just to name a few examples. You can also represent single, unique assets like a deed for a house, collectable items, unique parts on a supply chain, etc. There is also ABI_CODEC functionality to place transfer restrictions on an asset that help support securities, compliance, and certification use cases.
Info
Assets that represent many of the same type, like a stablecoin, may be referred to as fungible assets. Single, unique assets are referred to as non-fungible assets.
This section begins with an overview of the asset implementation on Algorand including a review of all asset parameters. This is followed by how-tos in the SDKs and goal
for all on-chain asset functions.
Quick start videos¶
If you prefer videos, take a look at this 7 minute guide to learn about Introduction to Assets.
Assets overview¶
Here are several things to be aware of before getting started with assets.
- For every asset an account creates or owns, its minimum balance is increased by 0.1 Algos (100,000 microAlgos).
- This minimum balance requirement will be placed on the original creator as long as the asset has not been destroyed. Transferring the asset does not alleviate the creator's minimum balance requirement.
- Before a new asset can be transferred to a specific account the receiver must opt-in to receive the asset. This process is described below in Receiving an asset.
- If any transaction is issued that would violate the minimum balance requirements, the transaction will fail.
Info
Prior to AVM 1.1 (go-algorand 3.5.0), a single Algorand account was only permitted to create and optin to 1000 assets. These limits are now removed allowing an unlimited number of assets to be created and optin to by a single account.
Asset parameters¶
The type of asset that is created will depend on the parameters that are passed during asset creation and sometimes during asset re-configuration. View the full list of asset parameters in the Asset Parameters Reference.
Immutable asset parameters¶
These eight parameters can only be specified when an asset is created.
- Creator (required)
- AssetName (optional, but recommended)
- UnitName (optional, but recommended)
- Total (required)
- Decimals (required)
- DefaultFrozen (required)
- URL (optional)
- MetaDataHash (optional)
Mutable asset parameters¶
There are four parameters that correspond to addresses that can authorize specific functionality for an asset. These addresses must be specified on creation but they can also be modified after creation. Alternatively, these addresses can be set as empty strings, which will irrevocably lock the function that they would have had authority over.
Here are the four address types.
The manager account is the only account that can authorize transactions to re-configure or destroy an asset.
Warning
Never set this address to empty if you want to be able to re-configure or destroy the asset.
Specifying a reserve account signifies that non-minted assets will reside in that account instead of the default creator account. Assets transferred from this account are "minted" units of the asset. If you specify a new reserve address, you must make sure the new account has opted into the asset and then issue a transaction to transfer all assets to the new reserve.
Warning
The reserve account has no functional authority in the protocol. It is purely informational.
The freeze account is allowed to freeze or unfreeze the asset holdings for a specific account. When an account is frozen it cannot send or receive the frozen asset. In traditional finance, freezing assets may be performed to restrict liquidation of company stock, to investigate suspected criminal activity or to deny-list certain accounts. If the DefaultFrozen state is set to True, you can use the unfreeze action to authorize certain accounts to trade the asset (such as after passing KYC/AML checks).
Note
Just remember that DefaultFrozen is an immutable parameter and cannot be changed after creation.
Tip
Set this address to ""
if you want to prove to asset holders that the asset can never be frozen.
The clawback address represents an account that is allowed to transfer assets from and to any asset holder (assuming they have opted-in). Use this if you need the option to revoke assets from an account (like if they breach certain contractual obligations tied to holding the asset). In traditional finance, this sort of transaction is referred to as a clawback.
Tip
Set this address to ""
if you want to ensure to asset holders that assets can never be revoked.
If any of these four addresses is set to ""
that address will be cleared and can never be reset for the life of the asset. This will also effectively disable the feature of that address. For example setting the freeze address to ""
will prevent the asset from ever being frozen.
Asset functions¶
Quick start videos¶
If you prefer videos, take a look at this 8 minute guide to learn about Building Solutions Using ASAs.
Creating an asset¶
Transaction Authorizer: Any account with sufficient Algo balance
Create assets using either the SDKs or goal
. When using the SDKs supply all creation parameters. With goal
, managing the various addresses associated with the asset must be done after executing an asset creation. See Modifying an Asset in the next section for more details on changing addresses for the asset.
const suggestedParams = await algodClient.getTransactionParams().do();
const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
from: creator.addr,
suggestedParams,
defaultFrozen: false,
unitName: 'rug',
assetName: 'Really Useful Gift',
manager: creator.addr,
reserve: creator.addr,
freeze: creator.addr,
clawback: creator.addr,
assetURL: 'http://path/to/my/asset/details',
total: 1000,
decimals: 0,
});
const signedTxn = txn.signTxn(creator.privateKey);
await algodClient.sendRawTransaction(signedTxn).do();
const result = await algosdk.waitForConfirmation(
algodClient,
txn.txID().toString(),
3
);
const assetIndex = result['asset-index'];
console.log(`Asset ID created: ${assetIndex}`);
# Account 1 creates an asset called `rug` with a total supply
# of 1000 units and sets itself to the freeze/clawback/manager/reserve roles
sp = algod_client.suggested_params()
txn = transaction.AssetConfigTxn(
sender=acct1.address,
sp=sp,
default_frozen=False,
unit_name="rug",
asset_name="Really Useful Gift",
manager=acct1.address,
reserve=acct1.address,
freeze=acct1.address,
clawback=acct1.address,
url="https://path/to/my/asset/details",
total=1000,
decimals=0,
)
# Sign with secret key of creator
stxn = txn.sign(acct1.private_key)
# Send the transaction to the network and retrieve the txid.
txid = algod_client.send_transaction(stxn)
print(f"Sent asset create transaction with txid: {txid}")
# Wait for the transaction to be confirmed
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
# grab the asset id for the asset we just created
created_asset = results["asset-index"]
print(f"Asset ID created: {created_asset}")
// Account 1 creates an asset called `rug` with a total supply
// of 1000 units and sets itself to the freeze/clawback/manager/reserve roles
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Under the covers, this is an AssetConfig with asset id set to 0
Transaction createTxn = Transaction.AssetCreateTransactionBuilder().suggestedParams(sp)
.sender(acct.getAddress())
.assetTotal(1000)
.assetDecimals(0)
.defaultFrozen(false)
.assetUnitName("rug")
.assetName("Really Useful Gift")
.url("https://path/to/my/asset/details")
.manager(acct.getAddress())
.reserve(acct.getAddress())
.freeze(acct.getAddress())
.clawback(acct.getAddress())
.build();
SignedTransaction signedCreateTxn = acct.signTransaction(createTxn);
Response<PostTransactionsResponse> submitResult = algodClient.RawTransaction()
.rawtxn(Encoder.encodeToMsgPack(signedCreateTxn)).execute();
String txId = submitResult.body().txId;
PendingTransactionResponse result = Utils.waitForConfirmation(algodClient, txId, 4);
// Grab the asset id for the asset we just created
Long asaId = result.assetIndex;
System.out.printf("Created asset with id: %d\n", asaId);
// Configure parameters for asset creation
var (
creatorAddr = creator.Address.String()
assetName = "Really Useful Gift"
unitName = "rug"
assetURL = "https://path/to/my/asset/details"
assetMetadataHash = "thisIsSomeLength32HashCommitment"
defaultFrozen = false
decimals = uint32(0)
totalIssuance = uint64(1000)
manager = creatorAddr
reserve = creatorAddr
freeze = creatorAddr
clawback = creatorAddr
note []byte
)
// Get network-related transaction parameters and assign
txParams, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
// Construct the transaction
txn, err := transaction.MakeAssetCreateTxn(
creatorAddr, note, txParams, totalIssuance, decimals,
defaultFrozen, manager, reserve, freeze, clawback,
unitName, assetName, assetURL, assetMetadataHash,
)
if err != nil {
log.Fatalf("failed to make transaction: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Create Transaction: %s confirmed in Round %d with new asset id: %d\n",
txid, confirmedTxn.ConfirmedRound, confirmedTxn.AssetIndex)
goal asset create --creator <address> --total 1000 --unitname <unit-name> --asseturl "https://path/to/my/asset/details" --decimals 0 -d data
Note
The Algorand Foundation hosts many standards (ARCs) associated with asset creation. Conforming to these standards allows your apps/assets to work well with existing community tools that support them.
See also
Modifying an asset¶
Authorized by: Asset Manager Account
After an asset has been created only the manager, reserve, freeze and clawback accounts can be changed. All other parameters are locked for the life of the asset. If any of these addresses are set to ""
that address will be cleared and can never be reset for the life of the asset. Only the manager account can make configuration changes and must authorize the transaction.
const manager = accounts[1];
const configTxn = algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject({
from: creator.addr,
manager: manager.addr,
freeze: manager.addr,
clawback: manager.addr,
reserve: undefined,
suggestedParams,
assetIndex,
// don't throw error if freeze, clawback, or manager are empty
strictEmptyAddressChecking: false,
});
const signedConfigTxn = configTxn.signTxn(creator.privateKey);
await algodClient.sendRawTransaction(signedConfigTxn).do();
const configResult = await algosdk.waitForConfirmation(
algodClient,
txn.txID().toString(),
3
);
console.log(`Result confirmed in round: ${configResult['confirmed-round']}`);
sp = algod_client.suggested_params()
# Create a config transaction that wipes the
# reserve address for the asset
txn = transaction.AssetConfigTxn(
sender=acct1.address,
sp=sp,
manager=acct1.address,
reserve=None,
freeze=acct1.address,
clawback=acct1.address,
strict_empty_address_check=False,
)
# Sign with secret key of manager
stxn = txn.sign(acct1.private_key)
# Send the transaction to the network and retrieve the txid.
txid = algod_client.send_transaction(stxn)
print(f"Sent asset config transaction with txid: {txid}")
# Wait for the transaction to be confirmed
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Wipe the `reserve` address through an AssetConfigTransaction
Transaction reconfigureTxn = Transaction.AssetConfigureTransactionBuilder().suggestedParams(sp)
.sender(acct.getAddress())
.assetIndex(asaId)
.manager(acct.getAddress())
.freeze(acct.getAddress())
.clawback(acct.getAddress())
.strictEmptyAddressChecking(false)
.reserve(new byte[32])
.build();
creatorAddr := creator.Address.String()
var (
newManager = creatorAddr
newFreeze = creatorAddr
newClawback = creatorAddr
newReserve = ""
strictAddrCheck = false
note []byte
)
// Get network-related transaction parameters and assign
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
txn, err := transaction.MakeAssetConfigTxn(creatorAddr, note, sp, assetID, newManager, newReserve, newFreeze, newClawback, strictAddrCheck)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Asset Config Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset config --manager <address> --new-reserve <address> --assetid <asset-id> -d data
See also
Receiving an asset¶
Authorized by: The account opting in
Before an account can receive a specific asset it must opt-in to receive it. An opt-in transaction places an asset holding of 0 into the account and increases its minimum balance by 100,000 microAlgos. An opt-in transaction is simply an asset transfer with an amount of 0, both to and from the account opting in. The following code illustrates this transaction.
// opt-in is simply a 0 amount transfer of the asset to oneself
const optInTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: receiver.addr,
to: receiver.addr,
suggestedParams,
assetIndex,
amount: 0,
});
const signedOptInTxn = optInTxn.signTxn(receiver.privateKey);
await algodClient.sendRawTransaction(signedOptInTxn).do();
await algosdk.waitForConfirmation(algodClient, optInTxn.txID().toString(), 3);
sp = algod_client.suggested_params()
# Create opt-in transaction
# asset transfer from me to me for asset id we want to opt-in to with amt==0
optin_txn = transaction.AssetOptInTxn(
sender=acct2.address, sp=sp, index=created_asset
)
signed_optin_txn = optin_txn.sign(acct2.private_key)
txid = algod_client.send_transaction(signed_optin_txn)
print(f"Sent opt in transaction with txid: {txid}")
# Wait for the transaction to be confirmed
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Under the covers, this is an AssetTransfer from me to me for amount 0
// with asset id set to the asset we wish to start accepting
Transaction optInTxn = Transaction.AssetAcceptTransactionBuilder().suggestedParams(sp)
.sender(acct.getAddress())
.assetIndex(asaId)
.build();
userAddr := user.Address.String()
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
txn, err := transaction.MakeAssetAcceptanceTxn(userAddr, nil, sp, assetID)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(user.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("OptIn Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset send -a 0 --asset <asset-name> -f <opt-in-account> -t <opt-in-account> --creator <asset-creator> -d data
See also
Transferring an asset¶
Authorized by: The account that holds the asset to be transferred.
Assets can be transferred between accounts that have opted-in to receiving the asset. These are analogous to standard payment transactions but for Algorand Standard Assets.
const xferTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: creator.addr,
to: receiver.addr,
suggestedParams,
assetIndex,
amount: 1,
});
const signedXferTxn = xferTxn.signTxn(creator.privateKey);
await algodClient.sendRawTransaction(signedXferTxn).do();
await algosdk.waitForConfirmation(algodClient, xferTxn.txID().toString(), 3);
sp = algod_client.suggested_params()
# Create transfer transaction
xfer_txn = transaction.AssetTransferTxn(
sender=acct1.address,
sp=sp,
receiver=acct2.address,
amt=1,
index=created_asset,
)
signed_xfer_txn = xfer_txn.sign(acct1.private_key)
txid = algod_client.send_transaction(signed_xfer_txn)
print(f"Sent transfer transaction with txid: {txid}")
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Under the covers, this is an AssetTransfer from me to me for amount 0
// with asset id set to the asset we wish to start accepting
Transaction xferTxn = Transaction.AssetTransferTransactionBuilder().suggestedParams(sp)
.sender(sender.getAddress())
.assetReceiver(receiver.getAddress())
.assetIndex(asaId)
.assetAmount(1)
.build();
var (
creatorAddr = creator.Address.String()
userAddr = user.Address.String()
)
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
txn, err := transaction.MakeAssetTransferTxn(creatorAddr, userAddr, 1, nil, sp, "", assetID)
if err != nil {
log.Fatalf("failed to make asset txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Asset Transfer Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset send -a <asset-amount> --asset <asset-name> -f <asset-sender> -t <asset-receiver> --creator <asset-creator> -d data
See also
Freezing an asset¶
Authorized by: Asset Freeze Address
Freezing or unfreezing an asset for an account requires a transaction that is signed by the freeze account. The code below illustrates the freeze transaction.
const freezeTxn = algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject({
from: manager.addr,
suggestedParams,
assetIndex,
// freezeState: false would unfreeze the account's asset holding
freezeState: true,
// freezeTarget is the account that is being frozen or unfrozen
freezeTarget: receiver.addr,
});
const signedFreezeTxn = freezeTxn.signTxn(manager.privateKey);
await algodClient.sendRawTransaction(signedFreezeTxn).do();
await algosdk.waitForConfirmation(
algodClient,
freezeTxn.txID().toString(),
3
);
sp = algod_client.suggested_params()
# Create freeze transaction to freeze the asset in acct2 balance
freeze_txn = transaction.AssetFreezeTxn(
sender=acct1.address,
sp=sp,
index=created_asset,
target=acct2.address,
new_freeze_state=True,
)
signed_freeze_txn = freeze_txn.sign(acct1.private_key)
txid = algod_client.send_transaction(signed_freeze_txn)
print(f"Sent freeze transaction with txid: {txid}")
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Set the freeze state on the account, only the account that is set to the
// freeze role
// on the asset may issue this transaction
Transaction freezeTxn = Transaction.AssetFreezeTransactionBuilder().suggestedParams(sp)
.sender(sender.getAddress())
.freezeTarget(receiver.getAddress())
.freezeState(true)
.assetIndex(asaId)
.build();
var (
creatorAddr = creator.Address.String()
userAddr = user.Address.String()
)
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
// Create a freeze asset transaction with the target of the user address
// and the new freeze setting of `true`
txn, err := transaction.MakeAssetFreezeTxn(creatorAddr, nil, sp, assetID, userAddr, true)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Freeze Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset freeze --freezer <asset-freeze-account> --freeze=true --account <account-to-freeze> --creator <asset-creator> --asset <asset-name> -d data
See also
Revoking an asset¶
Authorized by: Asset Clawback Address
Revoking an asset for an account removes a specific number of the asset from the revoke target account. Revoking an asset from an account requires specifying an asset sender (the revoke target account) and an asset receiver (the account to transfer the funds back to). The code below illustrates the clawback transaction.
const clawbackTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject(
{
from: manager.addr,
to: creator.addr,
// revocationTarget is the account that is being clawed back from
revocationTarget: receiver.addr,
suggestedParams,
assetIndex,
amount: 1,
}
);
const signedClawbackTxn = clawbackTxn.signTxn(manager.privateKey);
await algodClient.sendRawTransaction(signedClawbackTxn).do();
await algosdk.waitForConfirmation(
algodClient,
clawbackTxn.txID().toString(),
3
);
sp = algod_client.suggested_params()
# Create clawback transaction to freeze the asset in acct2 balance
clawback_txn = transaction.AssetTransferTxn(
sender=acct1.address,
sp=sp,
receiver=acct1.address,
amt=1,
index=created_asset,
revocation_target=acct2.address,
)
signed_clawback_txn = clawback_txn.sign(acct1.private_key)
txid = algod_client.send_transaction(signed_clawback_txn)
print(f"Sent clawback transaction with txid: {txid}")
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// revoke an asset from an account, only the account that is set to the clawback
// role
// on the asset may issue this transaction
Transaction clawbackTxn = Transaction.AssetClawbackTransactionBuilder().suggestedParams(sp)
.sender(sender.getAddress())
.assetClawbackFrom(receiver.getAddress())
.assetReceiver(sender.getAddress())
.assetIndex(asaId)
.assetAmount(1)
.build();
var (
creatorAddr = creator.Address.String()
userAddr = user.Address.String()
)
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
// Create a new clawback transaction with the target of the user address and the recipient as the creator
// address, being sent from the address marked as `clawback` on the asset, in this case the same as creator
txn, err := transaction.MakeAssetRevocationTxn(creatorAddr, userAddr, 1, creatorAddr, nil, sp, assetID)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Clawback Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset send -a <amount-to-revoke> --asset <asset-name> -f <address-of-revoke-target> -t <address-to-send-assets-to> --clawback <clawback-address> --creator <creator-address> -d data
See also
Opting Out of an Asset¶
Authorized by: The account opting out
An account can opt out of an asset at any time. This means that the account will no longer hold the asset, and the account will no longer be able to receive the asset. The account also recovers the Minimum Balance Requirement for the asset (0.1A).
// opt-out is an amount transfer with the `closeRemainderTo` field set to
// any account that can receive the asset.
// note that closing to the asset creator will always succeed
const optOutTxn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
from: receiver.addr,
to: creator.addr,
closeRemainderTo: creator.addr,
suggestedParams,
assetIndex,
amount: 0,
});
const signedOptOutTxn = optOutTxn.signTxn(receiver.privateKey);
await algodClient.sendRawTransaction(signedOptOutTxn).do();
await algosdk.waitForConfirmation(
algodClient,
optOutTxn.txID().toString(),
3
);
sp = algod_client.suggested_params()
opt_out_txn = transaction.AssetTransferTxn(
sender=acct2.address,
sp=sp,
index=created_asset,
receiver=acct1.address,
# an opt out transaction sets its close_asset_to parameter
# it is always possible to close an asset to the creator
close_assets_to=acct1.address,
amt=0,
)
signed_opt_out = opt_out_txn.sign(acct2.private_key)
txid = algod_client.send_transaction(signed_opt_out)
print(f"Sent opt out transaction with txid: {txid}")
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
userAddr := user.Address.String()
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
txn, err := transaction.MakeAssetTransferTxn(userAddr, creator.Address.String(), 0, nil, sp, creator.Address.String(), assetID)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(user.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("OptOut Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Opt out of the asset by setting the assetCloseTo parameter
Transaction optOutTxn = Transaction.AssetTransferTransactionBuilder().suggestedParams(sp)
.sender(sender.getAddress())
.assetReceiver(creator.getAddress())
.assetCloseTo(creator.getAddress())
.assetIndex(asaId)
.assetAmount(0)
.build();
Destroying an asset¶
Authorized by: Asset Manager
Created assets can be destroyed only by the asset manager account. All of the assets must be owned by the creator of the asset before the asset can be deleted.
const deleteTxn = algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject({
from: manager.addr,
suggestedParams,
assetIndex,
});
const signedDeleteTxn = deleteTxn.signTxn(manager.privateKey);
await algodClient.sendRawTransaction(signedDeleteTxn).do();
await algosdk.waitForConfirmation(
algodClient,
deleteTxn.txID().toString(),
3
);
sp = algod_client.suggested_params()
# Create asset destroy transaction to destroy the asset
destroy_txn = transaction.AssetDestroyTxn(
sender=acct1.address,
sp=sp,
index=created_asset,
)
signed_destroy_txn = destroy_txn.sign(acct1.private_key)
txid = algod_client.send_transaction(signed_destroy_txn)
print(f"Sent destroy transaction with txid: {txid}")
results = transaction.wait_for_confirmation(algod_client, txid, 4)
print(f"Result confirmed in round: {results['confirmed-round']}")
# now, trying to fetch the asset info should result in an error
try:
info = algod_client.asset_info(created_asset)
except Exception as e:
print("Expected Error:", e)
Response<TransactionParametersResponse> rsp = algodClient.TransactionParams().execute();
TransactionParametersResponse sp = rsp.body();
// Under the covers, an AssetDestroyTransaction is an AssetConfig with all of
// its
// configurable fields set to empty
// All units of the asset _must_ be owned by the creator account and this
// transaction _must_
// be issued by the account set to the manager role on the asset
Transaction destroyTxn = Transaction.AssetDestroyTransactionBuilder().suggestedParams(sp)
.sender(acct.getAddress())
.assetIndex(asaId)
.build();
var (
creatorAddr = creator.Address.String()
)
sp, err := algodClient.SuggestedParams().Do(context.Background())
if err != nil {
log.Fatalf("error getting suggested tx params: %s", err)
}
// Create a new clawback transaction with the target of the user address and the recipient as the creator
// address, being sent from the address marked as `clawback` on the asset, in this case the same as creator
txn, err := transaction.MakeAssetDestroyTxn(creatorAddr, nil, sp, assetID)
if err != nil {
log.Fatalf("failed to make txn: %s", err)
}
// sign the transaction
txid, stx, err := crypto.SignTransaction(creator.PrivateKey, txn)
if err != nil {
log.Fatalf("failed to sign transaction: %s", err)
}
// Broadcast the transaction to the network
_, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
log.Fatalf("failed to send transaction: %s", err)
}
// Wait for confirmation
confirmedTxn, err := transaction.WaitForConfirmation(algodClient, txid, 4, context.Background())
if err != nil {
log.Fatalf("error waiting for confirmation: %s", err)
}
log.Printf("Destroy Transaction: %s confirmed in Round %d\n", txid, confirmedTxn.ConfirmedRound)
goal asset destroy --creator <creator-address> --manager <asset-manager-address> --asset <asset-name> -d data
See also
Retrieve asset information¶
Retrieve an asset's configuration information from the network using the SDKs or goal
. Additional details are also added to the accounts that own the specific asset and can be listed with standard account information calls.
Info
The code below illustrates getting asset information without the Indexer. If you have the Indexer installed use the Indexer API to search for asset information.
const assetInfo = await algodClient.getAssetByID(assetIndex).do();
console.log(`Asset Name: ${assetInfo.params.name}`);
console.log(`Asset Params: ${assetInfo.params}`);
# Retrieve the asset info of the newly created asset
asset_info = algod_client.asset_info(created_asset)
asset_params: Dict[str, Any] = asset_info["params"]
print(f"Asset Name: {asset_params['name']}")
print(f"Asset params: {list(asset_params.keys())}")
// Retrieve the asset info of the newly created asset
Response<Asset> assetResp = algodClient.GetAssetByID(asaId).execute();
Asset assetInfo = assetResp.body();
System.out.printf("Asset Name: %s\n", assetInfo.params.name);
info, err := algodClient.GetAssetByID(assetID).Do(context.Background())
if err != nil {
log.Fatalf("failed to get asset info: %s", err)
}
log.Printf("Asset info for %d: %+v", assetID, info)
goal asset info --creator <creator-address> --asset unitname -d ~/node/data -w testwall
Asset ID: <created-asset-id>
Creator: <creator-address>
Asset name: testtoken
Unit name: unitname
Maximum issue: 12 unitname
Reserve amount: 12 unitname
Issued: 0 unitname
Decimals: 0
Default frozen: false
Manager address: <creator-address>
Reserve address: <reserve-address>
Freeze address: <freeze-address>
Clawback address: <clawback-address>