Skip to main content

Import ULedger SDK

In this example, we'll be connecting our program to a ULedger blockchain and blockchain services. This is important because, to successfully use the SDK, we need to create a session that will connect us with the network. Once this is set up, we'll be able to push and pull transactions.

info

To complete this example, please install the ULedger SDK. For additional information, please visit Getting Started

Create a Blockchain session

To create a blockchain session, we will need a few things, specifically from the ULedger portal. Assuming you have a blockchain with ULedger, please head over to the portal and retrieve your Node URL, Node Id, and the Atomic Clock URL. If you are unable to find this information, please feel free to reach out to the ULedger Support team.

Once you have your Node ID, Node URL, and Atomic Clock URL, we should be able to create a session with the blockchain using the following code. Make sure to replace the placeholder values with the information you retrieved for the Node Id, Node URL, and Atomic Clock URL.

// Required imports
import { ULedgerTransactionSession } from '@uledger/uledger-sdk';
// Create a new session
const session = new ULedgerTransactionSession(
{
nodeUrl: "{{NODE URL}}",
atomicClockUrl: "{{ACS URL}}",
nodeId: "{{NODE ID}}"
}
);

The constant we created, "session," will be used to make calls to the ULedger blockchain. This is important because it allows us to create transactions and submit data to the blockchain. For more information about creating transactions, please visit this tutorial.

Create a BMS session

What exactly is the BMS, and why do we need it? The BMS, or Blockchain Management System, is a centralized service that helps maintain the status of each blockchain. We need the BMS because it processes all of our queries. Whether we need to pull blocks, search for a transaction, or count the transactions we've created on-chain, we can send a request to the BMS.

To create the BMS session, we only need a URL to the service. However, if your blockchain is private, we will need Authorization. First, you will need to create a session for a public blockchain. After that, you will need to review the additional steps needed to create a session with a private blockchain.

info

If you are unable to find the BMS URL or need help retrieving Authorization for your private chain, please feel free to reach out to the ULedger Support team.

Creating a BMS Session with a public blockchain

In the code below, we are creating a session with the blockchain management service. Please replace the placeholder values with your BMS URL.

// Required imports
import { ULedgerBMSSession } from 'uledger-sdk';
// Create a new session
const session = new ULedgerBMSSession({
url: "{{MY_BMS_URL}}"
});

Creating a BMS Session with a private blockchain

In the code below, we are creating a session with the blockchain management service. This is for connecting to a private blockchain specifically. Please replace the placeholder values with your BMS URL and Authorization token.

// Required imports
import { ULedgerBMSSession } from 'uledger-sdk';
// Creating the instance of the Authorizer
const authorizer = new ApiKeyAuthorizer('MY_AUTH0_VALID_JWT');
// Create a new session
const session = new ULedgerBMSSession({
url: "{{MY_BMS_URL}}"
authorizer,
});
© 2023 ULedger Inc. All rights reserved