Assets
Each type of value in the ledger is called an asset. For example, if your application manages multiple currencies, you might create a USD asset, an EUR asset, and a CNY asset.
On this page
Once an asset is created, you can issue tokens of that asset into an account.
Onyx Mesh represents amounts as integers in the range 0 to 2^63 - 1 (9,223,372,036,854,775,807).
It you want to represent an amount outside this range, such as Ethereum's wei, which has amounts in the range 0 to 2^256 we recommend using a smaller unit, such as gwei (aka shannon, nanoether).
IDLink to this section
A asset ID is a user-defined, unique identifier. If you do not provide one, one will be automatically generated for you.
Keys & QuorumLink to this section
When creating an asset, you provide one or more keys and a quorum. The quorum is the number of keys that must sign a transaction in order to issue tokens of the asset into the ledger. By default, the quorum is equal to the number of keys provided, but you can choose to require only a subset of keys – for example, 2-of-3.
Asset TagsLink to this section
Asset tags are user-defined key-value pairs associated with the asset. Asset tags are useful for grouping different assets together for the purpose of querying tokens or actions.
For example, if you have three assets that each represent a series of the same bond – series A, series B and series C – they could all carry the tag "type": "bond". Then, when you want the total amount issued across all of them, you would provide the following filter to the sum actions query:
type='issue' AND snapshot.assetTags.type='bond'type='issue' AND snapshot.assetTags.type='bond'type='issue' AND snapshot.asset_tags.type='bond'This would return a single aggregate sum of all actions issuing tokens across all three assets.
Tags snapshotLink to this section
When a new action is added to a ledger via a transaction, a snapshot of the asset tags as they exist at that time are added to the snapshot object in the action object.
You can then provide a filter to access the tags snapshot when querying actions. For example:
snapshot.assetTags.type='bond'snapshot.assetTags.type='bond'snapshot.asset_tags.type='bond'Updating tagsLink to this section
You can update asset tags at any time. These new tags will be added to the snapshot on any new actions going forward. Snapshots on existing actions will not be affected.
Data StructureLink to this section
Field DescriptionsLink to this section
| Field | Type | Description |
|---|---|---|
| id | string | Unique identifier of the asset, user-supplied or system-generated. |
| tags | JSON object | Arbitrary, user-supplied, key-value data about the asset. |
| key ids | array | A list of ids of the keys that control issuance of the asset. |
| quorum | integer | The number of keys from which signatures are required to issue units of the asset. |
Example ObjectLink to this section
{
id: "...",
tags: {},
keyIds: [],
quorum: 1
}{
id: "...",
tags: {},
keyIds: [],
quorum: 1
}{
id: "...",
tags: {},
key_ids: [],
quorum: 1
}SDK ExamplesLink to this section
Create an assetLink to this section
Asset usd = new Asset.Builder()
.setId("usd")
.addKeyId(key.id)
.addTag("type", "currency")
.create(ledger);ledger.assets.create({
id: 'usd',
keyIds: [key.id],
tags: {type: 'currency'}
}).then(usd => ...)usd = ledger.assets.create(
id: 'usd',
key_ids: [key.id],
tags: {type: 'currency'}
)Update asset tagsLink to this section
new Asset.TagUpdateBuilder()
.setId("usd")
.addTag("type", "fiat")
.update(ledger);ledger.assets.updateTags({
id: 'usd',
tags: {type: 'fiat'}
}).then(usd => ...)ledger.assets.update_tags(
id: 'usd',
tags: {type: 'fiat'}
)Query assetsLink to this section
Query all "currency" assets.
Asset.ItemIterable assets = new Asset.ListBuilder()
.setFilter("tags.type=$1")
.addFilterParameter("fiat")
.getIterable(ledger);
for (Asset asset : assets) {
System.out.println("asset": " + asset.id);
}let all = ledger.assets.list({
filter: 'tags.type=$1',
filterParams: ['fiat']
}).all()
while (true) {
let { value: asset, done: done } = await all.next()
if (done) { break }
console.log(asset)
}ledger.assets.list(
filter: 'tags.type=$1',
filter_params: ['fiat']
).each do |asset|
puts asset.to_json
end