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

@ergolabs/ergo-sdk

v0.5.7

Published

Ergo SDK

Downloads

15

Readme

Ergo SDK

npm version

This SDK includes:

  • Ergo protocol data model
  • Ergo wallet
  • Ergo Blockchain Explorer API wrapper

Usage

This SDK heavily relies on ergo-rust via WASM. So you have to load RustModule before using this SDK:

import React, { useEffect, useState } from 'react';
import { GeistProvider } from '@geist-ui/react';
import { RustModule } from '@ergolabs/ergo-sdk';

export const App: React.FC = () => {
  const [isRustModuleLoaded, setIsRustModuleLoaded] = useState(false);

  useEffect(() => {
    RustModule.load().then(() => setIsRustModuleLoaded(true));
  }, []);

  if (!isRustModuleLoaded) {
    return null;
  }

  return (<GeistProvider>...</GeistProvider>)
}

Ergo data model

  • Address
  • ErgoTree
  • ErgoTreeTemplate
  • ErgoBox
  • ErgoBoxCandidate
  • Input
  • DataInput
  • UnsignedInput
  • ErgoTx
  • UnsignedErgoTx
  • AssetAmount
  • AssetInfo
  • TokenAmount
  • Constant
  • ContextExtension
  • NetworkContext
  • ProverResult
  • PublicKey
  • Registers
  • SigmaType

Ergo Wallet

  • BoxSelector - Selects inputs satisfying a given target balance and tokens.
  • Prover - An interface of an abstract prover capable of signing transactions. Should be implemented using wallet integration (e.g. Yoroi).
  • TxAssembler - A service for simplified TX assembly.

Ergo Explorer API

Explorer API methods also rely on the Ergo data model, but most of them return enriched versions of Ergo models marked with Aug* prefix.

Implemented methods:

  • getTx(id: TxId): Promise<AugErgoTx | undefined> - Get confirmed transaction by id.
  • getOutput(id: BoxId): Promise<AugErgoBox | undefined> - Get confirmed output by id.
  • getTxsByAddress(address: Address, paging: Paging): Promise<[AugErgoTx[], number]> - Get transactions by address.
  • getUTxsByAddress(address: Address, paging: Paging): Promise<[AugErgoTx[], number]> - Get unconfirmed transactions by address.
  • getUnspentByErgoTree(tree: ErgoTree, paging: Paging): Promise<[AugErgoBox[], number]> - Get unspent boxes with a given ergoTree.
  • getUnspentByErgoTreeTemplate(hash: HexString, paging: Paging): Promise<AugErgoBox[]> - Get unspent boxes with scripts matching a given hash of ErgoTree template.
  • getUnspentByTokenId(tokenId: TokenId, paging: Paging, sort?: Sorting): Promise<AugErgoBox[]> - Get unspent boxes containing a token with a given id.
  • getByTokenId(tokenId: TokenId, paging: Paging, sort?: Sorting): Promise<AugErgoBox[]> - Get boxes containing a token with a given id.
  • getUnspentByErgoTreeTemplateHash(hash: HexString, paging: Paging): Promise<[AugErgoBox[], number]> - Get unspent boxes by a given hash of ErgoTree template.
  • searchUnspentBoxes(req: BoxSearch, paging: Paging): Promise<[AugErgoBox[], number]> - Detailed search among unspent boxes.
  • searchUnspentBoxesByTokensUnion(req: BoxAssetsSearch, paging: Paging): Promise<[AugErgoBox[], number]> - Search among unspent boxes by ergoTreeTemplateHash and tokens.
  • getFullTokenInfo(tokenId: TokenId): Promise<AugAssetInfo | undefined> - Get a token info by id.
  • getTokens(paging: Paging): Promise<[AugAssetInfo[], number]> - Get all available tokens.
  • getNetworkContext(): Promise<NetworkContext> - Get current network context.
import {Explorer} from "@ergolabs/ergo-sdk";
const explorer = new Explorer("https://api.ergoplatform.com");
const txId = "18b30e9b40ed7061d2f87590c555d24a712df9c848a8db9dfd4affcc92d3cb02";
explorer.getTx(txId).then(tx => console.log(tx));

Using with create-react-app

CRA does not support WASM. But you can workaround it. You need to override webpack config. Check out - https://stackoverflow.com/questions/59319775/how-to-use-webassembly-wasm-with-create-react-app/59720645#59720645