CreateAssetTx is used to create a new asset on the chain. An asset can contain whatever data you put inside the data field: merchandise, goods, certificate, string...

After CreateAssetTx is executed, an asset is created with a unique addree and the owner is the account that sent the CreateAssetTx . The asset could be transferred/exchanged to/with others. The use cases for asset are pretty rich, e.g.:

Sample Code

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;
NameData TypeDescriptionRequired
monikerstringThe nick name for the asset
readonlyboolWhether or not the asset is modifiable. By default it's False: an asset could be modified later by using update_asset,
transferrableboolwhether or not the asset can be transferred to others. By default it is True: the asset can be transferred.
ttlintTime To Live(ttl) means how long the asset is availiable after first consumption. By default it is 0, which 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.
parentstringParent 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.
addressstringpre-computed asset address. This field is required, however Forge SDK will help to calculate the address.Yes
data (optional)Google.Protobuf.AnyCustom user dataYes

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;

Sample Usage

> wallet = ForgeSdk.create_wallet()
> ForgeSdk.declare( "sisyphus"), wallet: wallet)
> ticket = "ticket_12345"
> itx = "fg:x:string", data: ticket), readonly: true, transferrable: true, ttl: 7200)
> ForgeSdk.create_asset(itx, wallet: wallet)

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 hashtodid / pkhashtodid 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)