Defining an Asset: Transaction Building

Users interact with the Findora Ledger through transactions. Transactions contain a set of operations interpretable by the ledger that can change the state of the ledger if certain conditions are met. We'll go over how to construct a transaction with a fairly common operation: DefineAsset.

An asset definition operation registers an asset with the Findora Ledger. An asset is a digital resource that can be issued and transferred. An asset has an issuer and a unique code. The DefineAsset operation must provide an unused token code. The transaction containing the DefineAsset operation will fail if there is already another asset on the ledger with the same code.

There are a couple of ways to create a token code but we'll use the simplest method here, random generation:

console.log('Creating a random token code...');
const tokenCode = Ledger.random_asset_type();
console.log(`Token code is ${tokenCode}...`);

Now we'll simulate a user using her key store to generate an issuer key and construct a transaction that creates a new asset.

console.log('Creating key store and generating an issuance key for Alice...');
const PASSWORD = 'findorarocks123';
const keyStore = new KeyStore.KeyStore(PASSWORD);
const masterKey = keyStore.genMasterKey(PASSWORD);
const aliceKeyPair = keyStore.genKeyPair(masterKey, 'Alice');

Alice will now create a transaction consisting of a single DefineAsset operation:

const memo = 'this is a test asset'; // Text that can be attached to an asset definition.
const assetRules = Ledger.AssetRules.new(); // Rules that restrict issuances and transfers involving this asset. To be covered in greater depth in another example. For now, use the default rules.
const blockCount = BigInt(0); // Necessary to prevent replays. If starting out, do not worry about this for now. If Alice were submitting this transaction to a live ledger, she would need to set this to the Ledger block count.
console.log('Creating a transaction with an asset definition operation...');
const definitionTransaction = Ledger.TransactionBuilder
  .new(blockCount).add_operation_create_asset(aliceKeyPair, memo, tokenCode, assetRules).transaction();
console.log('Operation created!');