Create Asset Transaction

Create Asset transaction is used to create a new asset for your account. The asset could be transferred/exchanged to/with others. The use cases for asset are pretty rich, e.g.:

  • merchandise
  • second hand goods
  • certificate
  • items in game
  • ...

Protocol definition

To create an asset you shall use CreateAssetTx message:

message CreateAssetTx {
  string moniker = 1;
  google.protobuf.Any data = 2;
  bool readonly = 3;
  bool transferrable = 4;
  uint32 ttl = 5;
  string parent = 6;
  string address = 7;
}
1
2
3
4
5
6
7
8
9

The most important field for an asset is its data - it could be anything that encoded into a google.protobuf.Any. Application can define and explain what's inside data, for example, if the asset is a movie ticket, application could define a Ticket message:

message Ticket {
  string row = 1;
  string seat = 2;
  string room = 3;
  string time = 4;
  string name = 5;
}
1
2
3
4
5
6
7

Other than the data field, all other fields are optional:

  • moniker: the nick name for the asset.
  • readonly: whether or not the asset is modifiable. By default an asset could be modified later by using update_asset.
  • transferrable: whether or not the asset can be transferred to others. By default it is not allowed to be transferred.
  • ttl: ttl for the asset after first consumption. By default it is unlimited usage. This is used when an asset is something like a park ticket, it could be valid for 24 hours after first use, or if it is an annual park permit, it could be valid for 365 days.
  • parent: parent asset for this asset. For example, an event is an asset, and all the tickets generated by this event will set its parent to the event address.
  • address: pre-computed asset address. This field is required, however Forge SDK will help to calculate the address.

Here's an example of creating an asset:

> wallet = ForgeSdk.create_wallet()
> ForgeSdk.declare(ForgeAbi.DeclareTx.new(moniker: "sisyphus"), wallet: wallet)
> ticket = ForgeAbi.Ticket.new(row: "K", seat: "22", room: "3A", time: "03/04/2019 11:00am PST", name: "Avengers: Endgame")
> itx = ForgeAbi.CreateAsset.new(data: ForgeSdk.encode_any!(ticket), readonly: true, transferrable: true, ttl: 7200)
> ForgeSdk.create_asset(itx, wallet: wallet)
1
2
3
4
5

Calculating asset address

If unfortunately your language has no SDK support, you need to calculate the address yourself. Below is the algorithm and elixir code to build asset address:

  • encode filled the CreateAssetTx itx to binary
  • do sha3 to it
  • use hash_to_did / pkhash_to_did to generate the did (type shall be asset)
hash = Mcrypto.hash(%Mcrypto.Hasher.Sha3{}, ForgeAbi.CreateAssetTx.encode(itx))
AbtDid.hash_to_did(:asset, hash, form: :short)
1
2
Last Updated: 7/17/2019, 7:58:17 AM