Skip to content

sergmetelin/blade-web3.js

 
 

Repository files navigation

Blade Web3 JavaScript API

npm version

A JavaScript/TypeScript library for development of DApps using Blade Wallet on Hedera Network

Documentation

Read the TypeDoc API documentation

Example Usage

For example usage and testing the below APIs using a Demo App, please go here and setup the app locally:

The hosted version of the Demo App can be used to try out some API calls:

Getting Started

Blade Wallet uses the Hedera Signature and Wallet Interface as defined here.

Installation

This package is available as a NPM package.

npm install @bladelabs/blade-web3.js

Usage

The BladeSigner class implements the Hashgraph Signer interface and allows access to Blade Wallet operations.

To interact with the Blade Extension programmatically, instantiate a BladeSigner object and create a new session.

import {BladeSigner} from 'blade-web3.js';


initBlade();

async function initBlade() {

    const bladeSigner = new BladeSigner();
    await bladeSigner.createSession();

    // bladeSigner object can now be used.
    bladeSigner.getAccountId();

}

you can then communicate with the Extension using the BladeSigner object using the Hedera Signer interface:

API Description
bladeSigner.getAccountId() Get accountId of active account.
bladeSigner.getAccountBalance( accountId:AccountId|string)
bladeSigner.getAccountInfo( accountId:AccountId|string) Get information about a Hedera account on the connected network.
bladeSigner.checkTransaction(transaction:Transaction) Check that a transaction is valid.
bladeSigner.populateTransaction(transaction:Transaction) Set transaction id with active account.
bladeSigner.sendRequest(request:Executable) Sign and execute a transaction with provider account.
bladeSigner.signTransaction(transaction:Transaction) Sign a transaction with active wallet account.
bladeSigner.getLedgerId() Ledger Id of the currently connected network.
bladeSigner.getMirrorNetwork() Return array of mirror nodes for the current network.
bladeSigner.getNetwork() Get map of nodes for the current hedera network.

Executing a Transfer:

import { TransferTransaction } from '@hashgraph/sdk';

 const amount = new BigNumber(5);

 const transaction = new TransferTransaction(
    {
          hbarTransfers: [{
            accountId: destinationAccountId,
            amount: amount
          },
          {
            accountId: bladeSigner.getAccountId(),
            amount: amount.negated()
          }
          ]
        }

      );

const result = await bladeSigner.sendRequest(transaction);

Getting a transaction receipt:

import { TransactionReceiptQuery } from '@hashgraph/sdk';

const result = await bladeSigner.sendRequest( new TransactionReceiptQuery({transactionId:transactionId}));

License

This repository is distributed under the terms of the Apache License (Version 2.0). See LICENSE for details.

About

JavaScript library to interact with Blade Wallet

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%