Giter Site home page Giter Site logo

cooper-kunz / hedera-sdk-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hashgraph/hedera-sdk-js

0.0 1.0 0.0 8.1 MB

Hedera™ Hashgraph SDK for JavaScript/TypeScript

Home Page: https://docs.hedera.com/docs/hedera-sdks

License: Apache License 2.0

TypeScript 98.97% JavaScript 0.79% Shell 0.23%

hedera-sdk-js's Introduction

Hedera Hashgraph's Javascript/TypeScript SDK

Actions Status npm Documentation NPM

The Javascript/Typescript SDK for interacting with Hedera Hashgraph: the official distributed consensus platform built using the hashgraph consensus algorithm for fast, fair and secure transactions. Hedera enables and empowers developers to build an entirely new class of decentralized applications.

Usage

This SDK supports both running in the browser (with Webpack) and in Node.

(Code examples using await assume an async context.)

Installation

# with NPM
$ npm install --save @hashgraph/sdk
# with Yarn
$ yarn add @hashgraph/sdk

Creating a client

import {Client} from "@hashgraph/sdk";

const client = new Client({ 
    // this key defaults to this url, a public free proxy to the Hedera public testnet
    // generously hosted by MyHederaWallet.com
    network: { "https://grpc-web.myhederawallet.com": "0.0.3" },
    operator: {
        // the account which signs transactions and query payments by default
        account: { shard: 0, realm: 0, account: ___ },
        // the private key used to sign the transactions, either encoded as a string
        // or as an `Ed25519PrivateKey` type 
        privateKey: "..."
    },
});

Checking your balance

console.log('current account balance:', await client.getAccountBalance());

Sending a transfer

// the amount parameter can either be a `number` or a bignumber.js type
new CryptoTransferTransaction()
    .addSender({ shard: 0, realm: 0, account: ___ }, 10_000_000)
    .addRecipient({ shard: 0, realm: 0, account: ___ }, 10_000_000)
    .build(client)
    .execute(client);

Creating a new Account

import { Ed25519PrivateKey } from "@hashgraph/sdk";

const privateKey = await Ed25519PrivateKey.generate();
const publicKey = privateKey.publicKey;

const tx = new AccountCreateTransaction()
    .setKey(privateKey.publicKey)
    .setInitialBalance(0)
    .build(client);

await tx.execute(client);
const receipt = await tx.getReceipt(client);
const newAccount = receipt.accountId;

console.log('new account: ', newAccount, 'public key: ', publicKey.toString(), ' private key: ', privateKey.toString());

Running locally

Do you want to run this SDK locally or help contribute?

Checkout the DEVELOPING.md file to get started!

Proxying from a browser

By default, you can specify which nodes you'd like to submit to, but this assumes that you're running in a server environment. If you're running from the browser, the SDK defaults to a gRPC proxy hosted by myhbarwallet and the LaunchBadge team. If you'd like to run your own proxy, please checkout the PROXY.md file to get setup!

DISCLAIMER

This project is actively under development and not recommended for production use. Join the Hedera discord for the latest updates and announcements.

LICENSE

Copyright 2019 Hedera Hashgraph LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

hedera-sdk-js's People

Contributors

abonander avatar cooper-kunz avatar dependabot[bot] avatar janaakhterov avatar kenthejr avatar mehcode avatar questofiranon avatar

Watchers

 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.