developers

Read the full documentation on Read the Docs!

Quick Start

Setup

Prerequisites:
  • Node version 9.x

 

Install

  1. Install Activeledger
$> npm i -g @activeledger/activeledger @activeledger/activerestore @activeledger/activecore
  • Run

    // Start a single node
    $> activeledger
    // OR setup a 3 node test network
    // Optional: add a number after testnet to create that many instances
    $> activeledger --testnet
    // Replace x with the instance number
    // Repeat for all instances created
    $> cd instance-x
    $> activeledger
  • Instance zero can be accessed at http://localhost:5260, the API will be available on http://localhost:5261 with the API explorer on http://localhost:5261/explorer

Read more about the testnet here.

Transacting

The following is an example of the bare minimum required for a transaction.

Namespace: The registered namespace linked to the sigining identity.

Contract StreamID: The ID of the contract running the transaction as generated by the ledger when the contract was uploaded.

Input Data: Data input as defined by the contract.

Identity: The identity that is running the transaction and owns the namespace and contract.

Signature of $tx object: The signature of the transaction.

{ 
    "$tx": { 
        "$namespace": "[namespace]",
        "$contract": "[contract streamid]", 
        "$i": { 
            [input data]
         } 
     },
    "$sigs": { 
        "identity": "[signature of $tx object]" 
    }
}

Integrating with your application

Integrating Activeledger into your application is simple.

  1. Build a transaction object as detailed above and in the documentation
  2. Populate the transaction inputs and outputs as defined by the smart contract
  3. Sign the transaction
  4. Post the signed transaction object to the ledger connection

Signing a transaction

Typescript

import { ActiveCrypto } from "@activeledger/activecrypto";

class ClassName {

  constructor(
    private activeCrypto: ActiveCrypto
  ) {}

  public signTransaction(tx: string, key: KeyDataType): Promise<string> {
    return new Promise<string>((resolve, reject) => {

      const keyPair = new this.activeCrypto.KeyPair(
        key.encryption,
        key.prv.pkcs8pem
      );

      resolve(keyPair.sign(tx));
    });
  }
}
const key: KeyData = key;
const transactionToSign = JSON.stringify(transaction.$tx);

signTransaction(transactionToSign, key)
.then((signature: string) => {
  transaction.$sigs[key.identity] = signature;
})
.catch((error: any) => {...})

***

Tools

Active Harmony

Active Harmony is a feature rich IDE and Ledger management tool that can be used to manage connections, keys, namespaces and contracts. In addition to the management elements Active Harmony allows you to develop smart contracts directly in the application, upload them to a ledger and run them.

Coming soon!

***

***

Leave a Reply

Your email address will not be published. Required fields are marked *