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

@uniworld/unichain-js

v1.1.0

Published

JavaScript SDK that encapsulates the UNICHAIN HTTP API

Downloads

5

Readme

What is UnichainJS?

UniChainJS is a javascript library to work with Unichain network. It provides essential functions to manage a wallet, deploy smart contracts, build transactions, broadcast transactions to the network

Detailed document and API list can be found at the Developer page

How to use

  1. Install Unichain-JS by npm install @uniworld/unichain-js
  2. Import to javascript file const UniChainJS = require('@uniworld/unichain-js')
  3. Start using library

Example

const UnichainJS = require('@uniworld/unichain-js')

//initiate unichainjs
const unichain = new Unichain({
    fullHost: '127.0.0.1:6636',
    privateKey: 'your_private_key'
})

//check if it is connected
unichain.isConnected((err, data) => {
    if (err) return
    console.log('Connected to network')
})

//Generate account
const account = unichain.utils.accounts.generateAccount()
console.log(account)
/*
    { 
        privateKey:'7D1A95FDB7FDA1A53ABC5438AA85CD1B96070E46E9125B03C947A6839CA63C45',
        publicKey:'04D372E96F523842AAF65DE9A785F244AE68CB789F8949174E3E9041D8DDC52E94AFA1F611F6F5904D59D3D209EC95D16654E675A20BA079DEB89A018384D42FDF',
        address: { 
            base58: 'UYdL2g5bbYmkDTSywSfNRhAmCJJGHyUbEk',
            hex: '4474BFBC5DED85E491E3332FE285D58EEDFE365EDF' 
        } 
    }
*/

//Get transaction 
unichain.api.getTransaction(txid, (err, tx) => {
    console.log('Transaction:', tx)
})

//Build transaction offline and sending coin
const amount = 1000 
const fromAddress = 'UZQWseP7WEN1R3nukDtLksukSduCvB19eT'
const toAddress = 'UabADyuooKUrVgzzfiH8Q7LpDX7wKpd54t'
const data = {
    to_address: unichain.address.toHex(toAddress),
    owner_address: unichain.address.toHex(fromAddress),
    amount: amount
}
//private key of fromAddress
const testPriKey = '45438936af44f337242b9823df58aed1af559682c2dbc2f40205d2124e9c1133' 
const unsingedTx = await unichain.currentProviders().fullNode.request('wallet/createtransaction', data, 'post')
const signedTx = await unichain.api.signTransaction(unsingedTx, testPriKey, 0)
const res = await unichain.api.sendRawTransaction(signedTx)
console.log(res)

//Working with smart contract - for example simple coin smart contract
const contractAddress = 'UdVXfqQ4HAdvCoDqBc8zFjA49NfwvAfS7c'
const contract = unichainJs.contract()
const loadContract = await contract.at(contractAddress)
console.log(loadContract)
const balance = await contract.getBalance('US4CaJ5GPEg4teYiAhNTe53pSW4QN7QrDb').call()
console.log(balance.toNumber())
let res = await contract.sendCoin('UQZjUw5S87G9DsmNFoMPGuaGLJwkxWuUfV', 10).send()
console.log(res)

Contact

email:

[email protected]

website: