Mosaics created with the revokable flag allow their creator to reclaim units from any account,
returning them to the creator's own account balance.
This is useful for enforcing contractual terms, reclaiming unused tokens, or correcting erroneous distributions.
This tutorial shows how to revoke mosaic units from another account.
The snippet reads the signer's private key from the SIGNER_PRIVATE_KEY environment variable, which defaults to a test
key if not set.
The signer's address is derived from the public key.
This account must be the original creator of the mosaic with the revokable flag.
The SOURCE_ADDRESS environment variable specifies the address of the account from which mosaic units will be revoked.
The MOSAIC_ID environment variable specifies the hexadecimal identifier of the mosaic to revoke.
See Querying Account Balance to list the mosaics held by an account.
# Fetch current network timetime_path='/node/time'print(f'Fetching current network time from {time_path}')withurllib.request.urlopen(f'{NODE_URL}{time_path}')asresponse:response_json=json.loads(response.read().decode())receive_timestamp=(response_json['communicationTimestamps']['receiveTimestamp'])timestamp=NetworkTimestamp(int(receive_timestamp))print(f' Network time: {timestamp.timestamp} ms since nemesis')# Fetch recommended feesfee_path='/network/fees/transaction'print(f'Fetching recommended fees from {fee_path}')withurllib.request.urlopen(f'{NODE_URL}{fee_path}')asresponse:response_json=json.loads(response.read().decode())median_mult=response_json['medianFeeMultiplier']minimum_mult=response_json['minFeeMultiplier']fee_mult=max(median_mult,minimum_mult)print(f' Fee multiplier: {fee_mult}')
Before revoking, the helper function get_account_mosaics fetches the source account's current balance for the target
mosaic from the /accounts/{accountId}GET endpoint.
This provides a baseline to compare against after the revocation.
The revocation transaction reclaims mosaic units from the source account and returns them to the creator's balance:
Type: Mosaic supply revocation transactions use the type mosaic_supply_revocation_transaction_v1.
Source address: The address of the account holding the mosaic units to revoke.
This can be any account that currently holds units of the specified mosaic.
Mosaic: An object containing the mosaic ID and the amount to revoke.
Amount: The number of atomic units to revoke from the source account.
To find out the mosaic's divisibility,
query the /mosaics/{mosaicId}GET endpoint.
For example, with a divisibility of 2, an amount of 700 represents 7.00 whole units (700 / 102).
Partial revocation
The amount does not have to match the source account's full balance.
Any amount up to the source's current holdings can be revoked in a single transaction.
To verify the revocation, the helper function get_account_mosaics fetches the source account's balance again.
The balance should be lower than the initial balance by the revoked amount.
Using node https://reference.symboltest.net:3001
Signer address: TCHBDENCLKEBILBPWP3JPB2XNY64OE7PYHHE32I
Source address: TB6QOVCUOFRCF5QJSKPIQMLUVWGJS3KYFDETRPA
Mosaic ID: 8857803461494335809 (0x7aed3d514c986941)
Fetching current network time from /node/time
Network time: 104783268507 ms since nemesis
Fetching recommended fees from /network/fees/transaction
Fee multiplier: 100
--- Checking initial balance ---
Fetching account information from /accounts/TB6QOVCUOFRCF5QJSKPIQMLUVWGJS3KYFDETRPA
Mosaic ID: 7AED3D514C986941, Amount: 1000
--- Revoking mosaic ---
Built mosaic revocation transaction:
{
"signature": "225719859B43C8B9FCB04432E83FA95258C15A64B60974754DC2E4CAF9E58110995F2ECB5552049C3F79632FFAF19F4B90247012A7777E79D3AF0A17507A9F0D",
"signer_public_key": "3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29",
"version": 1,
"network": 152,
"type": 17229,
"fee": "16800",
"deadline": "104790468507",
"source_address": "987D075454716222F609929E883174AD8C996D5828C938BC",
"mosaic": {
"mosaic_id": "8857803461494335809",
"amount": "700"
}
}
Transaction hash: C0E59A5E36FC50CC5BDF8A16EABAB791611737B64E3590D43576374B803771E6
Announcing mosaic revocation to /transactions
Response: {"message":"packet 9 was pushed to the network via /transactions"}
Waiting for mosaic revocation confirmation...
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: unconfirmed
Transaction status: confirmed
Mosaic revocation confirmed in 8 seconds
--- Verifying revocation ---
Fetching account information from /accounts/TB6QOVCUOFRCF5QJSKPIQMLUVWGJS3KYFDETRPA
Mosaic ID: 7AED3D514C986941, Amount: 300
Some highlights from the output:
Mosaic ID (line 4): The mosaic ID 8857803461494335809 (0x7aed3d514c986941) identifies the mosaic to revoke.
Initial balance (line 12): Before the revocation, the source account holds 1000 atomic units of the mosaic.
Source address (line 24): The source_address field identifies the account from which units are revoked.
This is the hex-encoded form of the Base32 address shown on line 3.
Revoked amount (lines 26-27): The mosaic object specifies the mosaic ID in decimal format and the amount 700.
The decimal value corresponds to the hexadecimal ID shown on line 4.
Verified balance (line 47): After the revocation, the source account's balance is 300, confirming that 700
atomic units were successfully reclaimed.
The transaction hash printed in the output can be used to search for the transaction in the
Symbol Testnet Explorer.