Arxium

SDK walkthrough, part 2 of 3

Issue an asset from code

Register an asset with transfer rules, issue it and cap its holders in one script.

You play the issuer. The rules you set here are checked by the chain on every transfer, so no app, including yours, can skip them.

Before you start

  • arxium.mjs from the SDK quickstart.
  • Your key attested. Assets that require KYC check both ends of every transfer, including the issuer. In the Console, open Faucet and click Get attested.

1. Register, issue and set limits

issue.mjs
import { deriveAssetRef, encodeIssueAsset, encodeRegisterAsset, encodeSetAssetLimits } from "@arxiumlabs/sdk";import { me, rpc, send } from "./arxium.mjs"; // The asset's chain-wide reference is derived from your address and the id you pick.const asset = await deriveAssetRef(me.address, "fund-b"); await send(encodeRegisterAsset("fund-b", false, {  symbol: "FUNDB",  name: "Fund B",  asset_class: "equity",  decimals: 0,  required_claims: ["kyc"],      // every holder needs a KYC attestation  allowed_jurisdictions: null,   // any country  max_supply: 1_000_000n,  metadata_uri: null,}));await send(encodeIssueAsset(asset, 1000n));await send(encodeSetAssetLimits(asset, 100, 150n, null)); // at most 100 holders, 150 units each console.log(asset);console.log(await rpc.assets(me.address));
Terminal
node issue.mjsarxasset1tgm4953avgdva6xlwukkpvzymc8723qks5njjdktcrwyg6qu2adsnu75vl[ { ref: 'arxasset1tgm4…', symbol: 'FUNDB', balance: 1000, transfer_eligible: true, eligibility_reason: 'eligible', … } ]

Keep the arxasset1… reference: part 3 sends this asset. Because send waits for each block, the three actions land in order. Run the script a second time and registration is refused, because the id is already taken for your address:

Terminal
node issue.mjsActionDroppedError: action dropped: arx1k29t… already has an asset with id fund-b (arxasset1tgm4…)

2. The rest of the issuer's controls

Every other issuer action is one more send with its encoder. Only the issuer's key may send them.

  • encodeFreezeAsset(asset, true, reason) stops all transfers. Pass false to lift it.
  • encodeSetHolderFrozen(asset, holder, true) freezes one holder in both directions.
  • encodeLockHolderAmount and encodeLockHolderAmountUntil lock part of a balance.
  • encodeRecoverHolder moves a lost holder's position to a new address that passes the same checks.
  • encodeIssuerForcedTransfer moves units by court order or sanction. It skips the compliance checks and needs a reason.