Skip to content

Examples

Shin Neng edited this page Nov 14, 2023 · 12 revisions

NOTES:

There is a typescript project directly in this wiki repository with all the example sources - you can check it out and inspect:

  • git clone https://github.com/proximax-storage/tsjs-xpx-chain-sdk.wiki
    • see folder files/demo/src/demo

(those are referenced from other examples through Network class)

  • Get generationHash from block 1 (class NetworkProperties)
    • you need it as a mandatory parameter for every transaction signing
  • Wait for a transaction to be confirmed (method announceAndWaitForConfirmation)
  • Put all the http api endpoint classes into a single wrapper (class ApiEndpoint)
  • Generates new Keypair.
  • Generates a Keypair from a private key.
  • Generate Account struct.
  • Generate address from a public key.
  • Generate address from a private key.

Types of requests

  • Get AccountInfo for an account.
  • Get AccountsInfo for different accounts.
  • Get confirmed transactions information.
  • Get incoming transactions information.
  • Get outgoing transactions information.
  • Get unconfirmed transactions information.
  • Get aggregate bonded transactions information.
  • Get multisig account information.
  • Get multisig account graph information.
  • Get transaction information of transactionId or transactionHash.
  • Get transaction information for a given set of transactionId or transactionHash.
  • Get transaction status of transactionId or transactionHash.
  • Get an array of transaction statuses for a given set of transactionId or transactionHash.
  • Search transactions given transaction group type and transaction query params
  • Get mosaic information.
  • Get information for a set of mosaics.
  • Get readable names for a set of mosaics.
  • Get an array of MosaicInfo from mosaics created under provided namespace.
  • Get mosaic rich list
  • Get mosaic levy
  • Get namespace information.
  • Get namespaces an account owns.
  • Get readable names for a set of namespaces.
  • Get an array of NamespaceInfo for a given set of addresses.
  • Get metadata information given compositeHash.
  • Get metadatas information given compositeHashes.
  • Search metadata information given metadata query params.
  • Get BlockInfo for a given block height.
  • Get transactions from a block.
  • Get the current height of the chain.
  • Get the current score of the chain.
  • Get the storage information.
  • Get an array of BlockInfo for a given block height and limit.
  • Get the current network type of the chain.

Announces a transaction

  • Create a transfer transaction
  • Create a root namespace
  • Create a sub namespace
  • Create a mosaic definition transaction
  • Create a mosaic supply change transaction
  • Update mosaic levy
  • Remove mosaic levy
  • Update account metadata
  • Update mosaic metadata
  • Update namespace metadata
  • Create a modify multisig account transaction
  • AddExchangeOffer transaction

  • ExchangeOffer transaction

  • RemoveExchangeOffer transaction

  • Aggregate complete transaction

  • Aggregate bonded transaction

  • Aggregate cosignature transaction

  • Lock funds transaction

  • Scenario:
    • Seed account sends funds to both Alice and Bob in single aggregate complete transaction
    • Alice prepares and signs aggregate bonded transaction containing two inner transactions - one alice-to-bob and one bob-to-alice
    • Alice prepares and announces lock funds transactions for the above prepared aggregate bonded transaction
    • Alice announces the above prepared aggregate bonded transaction
    • Bob cosigns the aggregate bonded transaction from Alice and announces aggregate cosignature transaction
    • finally, the aggregate bonded transaction gets confirmed
  • Secret lock transaction

  • Secret proof transaction

  • Scenario - atomic cross-chain swap:
    • note: if secret lock is announced, it can be finalized only with the proof; this mechanism is utilized twice in atomic cross-chain swap
    • preconditions:
      • Alice and Bob have accounts in two different networks
      • Alice and Bob agreed on exchanging one mosaic from first network for another mosaic from second network
    • Alice announces secret lock transaction in network A using a secret (hash of the random proof), which locks the funds for Bob for claiming it later using the proof
    • Bob announces secret lock transaction in network B using the same secret as Alice, which locks the funds for Alice for claiming it later using the proof
    • Alice claims the funds locked by Bob in network B using the proof, announcing the proof publicly, so Bob can use it now, too
    • Bob claims the funds locked by Alice in network A using the proof
  • Subscribe a block channel
  • Subscribe a confirmedAdded channel
  • Subscribe a unconfirmedAdded channel
  • Subscribe a unconfirmedRemoved channel
  • Subscribe a partialAdded channel
  • Subscribe a partialRemoved channel
  • Subscribe a cosignature channel
  • Subscribe a status channel
Clone this wiki locally