npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@garizonchain/core

v0.0.2

Published

garizon core package

Downloads

5

Readme

@garizonchain/core

This package provides a collection of apis to interact with Garizon blockchain.

Installation

npm install @garizonchain/core

Usage

Create a Garizon instance connecting to testnet

const { Garizon } = require('@garizonchain/core');
const {
  ChainID,
  ChainType,
  hexToNumber,
  numberToHex,
  fromWei,
  Units,
  Unit,
} = require('@garizonchain/utils');

const gar = new Garizon(
    'https://api.s0.b.hmny.io/',
    {
        chainType: ChainType.Garizon,
        chainId: ChainID.GarTestnet,
    },
);

Getting balance of account gar103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7

gar.blockchain
  .getBalance({ address: 'gar103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7' })
  .then((response) => {
    console.log('balance in GARs: ' + fromWei(hexToNumber(response.result), Units.gar));
  });

Getting the latest block number

gar.blockchain.getBlockNumber().then((response) => {
  console.log('current block number: ' + hexToNumber(response.result));
});

Getting the block using block hash

gar.blockchain
  .getBlockByHash({
    blockHash: '0x08c46ae7249362a7d1f602d44c5a81f33ebdab6a7dcb6068f99610b57911aafd',
  })
  .then((response) => {
    console.log(response.result);
  });

Getting the block using block number

gar.blockchain
  .getBlockByNumber({
    blockNumber: numberToHex(422635),
  })
  .then((response) => {
    console.log(response.result);
  });

Getting the transaction using hash

gar.blockchain
  .getTransactionByHash({
    txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831',
  })
  .then((response) => {
    console.log(response.result);
  });

Getting the transaction receipt

gar.blockchain
  .getTransactionReceipt({
    txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831',
  })
  .then((response) => {
    console.log(response.result);
  });

Getting the cross-stage transaction receipt

gar.blockchain
  .getCxReceiptByHash({
    txnHash: '0xcd36a90ff5d5373285c2896ba7bbcd3f5324263c0cb8ecfb7cad2f5fc2fbdbda',
    stageID: 1,
  })
  .then((value) => {
    console.log(value.result);
  });

Getting the deployed smart contract code

gar.blockchain
  .getCode({
    address: '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19',
    blockNumber: 'latest',
  })
  .then((response) => {
    console.log(response.result);
  });

Getting the transaction count of an account

gar.blockchain
  .getTransactionCount({
    address: 'gar1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
  })
  .then((response) => {
    console.log(hexToNumber(response.result));
  });

Getting the stage structure and details

gar.blockchain.getStagingStructure().then((response) => {
  console.log(response.result);
});

Transferring funds using sendTransaction

// key corresponds to gar103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
gar.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');

async function transfer() {
  const txn = gar.transactions.newTx({
    to: 'gar166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
    value: new Unit(1).asGar().toWei(),
    // gas limit, you can use string
    gasLimit: '21000',
    // send token from stageID
    stageID: 0,
    // send token to toStageID
    toStageID: 0,
    // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
    gasPrice: new gar.utils.Unit('1').asGwei().toWei(),
  });

  // sign the transaction use wallet;
  const signedTxn = await gar.wallet.signTransaction(txn);
  const txnHash = await gar.blockchain.sendTransaction(signedTxn);
  console.log(txnHash.result);
}

transfer();