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

xphere

v1.0.3

Published

Xphere Javascript API

Downloads

42

Readme

Xphere.js

Xphere.js is a TypeScript implementation of the Xphere JavaScript API maintained by Seoul Labs.

Installation

You can install the package using NPM, Yarn, Pnpm or Bun

Using NPM

npm install xphere

Using Yarn

yarn add xphere

Using Pnpm

pnpm install xphere

Using Bun

bun add xphere

Getting Started

  1. Create a Key Pair
import XPHERE from "xphere";

const keypair = XPHERE.Sign.keyPair();

console.log(keypair);

Here is an example output of a generated key pair.

{
  private_key: 'ad242f114b0bf83860dd9d250de312980c957bd78e01ce02a3e24eefeb3b9b17',
  public_key: 'da2b3f4f5f58c1e3eb05a9c118a04da0ebdb54bfee98dbe75befab43042519df',
  address: '2d6c36dd80ea016c07bea6842522be57dc65927fd04e'
}

Now we can use this key pair to create transactions to be sent to the main-net or test-net environment.

  1. Query Balance

When creating your own example, please replace the value of 'privateKey' with the key pair you generated.

import XPHERE from 'xphere';

const peer = '127.0.0.1';

XPHERE.Rpc.endpoint(peer);

const privateKey = 'c0965d23e2c4d5745cdf2b1a5619e62cdec8f221d8b35555b1061641555aa17d';
const address = XPHERE.Sign.address(XPHERE.Sign.publicKey(privateKey));

const signedRequest = XPHERE.Rpc.signedRequest(
  {
    type: 'GetBalance',
    address: address,
  },
  privateKey,
);

const result = await XPHERE.Rpc.request(signedRequest);
const balance = result.data.balance;

console.log(balance);

Now the newly generated address has no balance.

For testing purposes, we have deployed a faucet contract on the test-net.

  1. Broadcast a Faucet Transaction
import XPHERE from 'xphere';

const peer = '127.0.0.1';

XPHERE.Rpc.endpoint(peer);

const privateKey = 'c0965d23e2c4d5745cdf2b1a5619e62cdec8f221d8b35555b1061641555aa17d';

const signedTransaction = XPHERE.Rpc.signedTransaction(
  {
    type: 'Faucet',
  },
  privateKey,
);

const result = await XPHERE.Rpc.broadcastTransaction(signedTransaction);

console.log(result);

After a few seconds, if you check the balance again, you can confirm that the balance has been added.

  1. Generate and Broadcast a Transaction

Since the decimal point of XP is 18 digits, you need to add 18 zeros to the 'amount'.

import XPHERE from 'xphere';

const peer = '127.0.0.1';

XPHERE.Rpc.endpoint(peer);

const privateKey = 'c0965d23e2c4d5745cdf2b1a5619e62cdec8f221d8b35555b1061641555aa17d';

const signedTransaction = XPHERE.Rpc.signedTransaction(
  {
    type: 'Send',
    to: '900b550aed04bd2a5fff2ed0a71d732595e126632635',
    amount: '125000000000000000000',
  },
  privateKey,
);

const result = await XPHERE.Rpc.broadcastTransaction(signedTransaction);

console.log(result);

If you need an example of writing a smart contract, please refer to the following repository.

  • Sample contracts: https://github.com/Seoullabs-official/contract-example