APIs
Blaze

Blaze

Blaze is a NodeJS library for creating Cardano transactions and off-chain code for your Cardano Smart Contracts in JavaScript. You can learn more about Blaze in their documentation site (opens in a new tab).

Blaze supports multiple backend providers for interacting with the Cardano network. One of those providers is U5C (short for UTxORPC) which is one of the APIs supported by Dolos. You can learn more about U5C in the U5C documentation.

Installation

To install the UTxORPC provider for blaze, use npm:

npm install @utxorpc/blaze-provider

You also need to install the Blaze SDK:

npm install @blaze-cardano/sdk

Sample Usage

Step 1: Import Blaze SDK and the UTxORPC Provider for Blaze

import {
    Bip32PrivateKey,
    mnemonicToEntropy,
    wordlist,
} from "@blaze-cardano/core";
import {
    HotWallet,
    Core,
    Blaze,
} from "@blaze-cardano/sdk";
import { U5C } from "@utxorpc/blaze-provider";

Step 2: Create a New U5C Provider with Dolos

Now this is where we can utilize our local Dolos node and use it for our UTxORPC provider. We can initiliaze our node through this link.

Here's how to create the U5C Provider:

const provider = new U5C({
    url: "http://localhost:50051",
});

Step 3: Create a New Wallet from a Mnemonic

const mnemonic = "your 24-word mnemonic here";
const entropy = mnemonicToEntropy(mnemonic, wordlist);
const masterkey = Bip32PrivateKey.fromBip39Entropy(Buffer.from(entropy), "");
const wallet = await HotWallet.fromMasterkey(masterkey.hex(), provider);

Step 4: Create a Blaze Instance from the Wallet and Provider

const blaze = await Blaze.from(provider, wallet);

Optional: Print the wallet address

console.log("Wallet address", wallet.address.toBech32());

Optional: Print the wallet balance

console.log("Wallet balance", (await wallet.getBalance()).toCore());

Step 5: Create an Example Transaction

const tx = await blaze
    .newTransaction()
    .payLovelace(
        Core.Address.fromBech32(
            "addr_test1qrnrqg4s73skqfyyj69mzr7clpe8s7ux9t8z6l55x2f2xuqra34p9pswlrq86nq63hna7p4vkrcrxznqslkta9eqs2nsmlqvnk",
        ),
        5_000_000n,
    )
    .complete();

Step 6: Sign the Transaction

const signedTx = await blaze.signTransaction(tx);

Step 7: Submit the Transaction to the Blockchain Network

const txId = await blaze.provider.postTransactionToChain(signedTx);

Conclusion

This showcases a use-case for Dolos which is through The UTxORPC (u5c) provider for Blaze (opens in a new tab). For further customization and advanced usage, refer to the documentation for Blaze (opens in a new tab). By understanding and utilizing these tools, you can develop robust applications that interact with Cardano efficiently.

Check the Blaze client example (opens in a new tab) in the Dolos repository for a working version of the above snippet.