Git Product home page Git Product logo

blade-web3.js's Introduction

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.

blade-web3.js's People

Contributors

justin-m-lacy avatar smian avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.