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

hear-verse

v0.0.20

Published

HearVerse is a Javascript library that provides an easy-to-use interface for interacting with a HearVerse Chain

Downloads

29

Readme

HearVerse

HearVerse is a Javascript library that provides an easy-to-use interface for interacting with a HearVerse Chain

Installation

npm i hear-verse

Usage

const HearVerse = require('hear-verse'); // adjust path to HearVerse file if necessary
const fs = require('fs');
const path = require('path');
const addressFilePath = path.join(__dirname, 'address.txt');

// replace this with your actual endpoint
const endpoint = 'ws://127.0.0.1:9944';

const api = new HearVerse(endpoint);

(async () => {
    await api.connect();

    async function getAccount() {
        if (fs.existsSync(addressFilePath)) {
            // If the file exists, read the address from it
            const address = fs.readFileSync(addressFilePath, 'utf8');
            return JSON.parse(address);
        } else {
            // If the file does not exist, create a new account
            const newAccount = await api.createAccount();
            // Write the address of the new account to the file
            fs.writeFileSync(addressFilePath, JSON.stringify(newAccount, null, 2));
            return newAccount;
        }
    }

    // Use the function like this:
    const account = await getAccount();

    // get balance
    const balance = await api.getBalance(account.address);

    console.log(`Balance of new account: ${balance}`);

    // get latest block
    const latestBlock = await api.getLatestBlock();


    // handling events
    const eventCallback = (eventData) => {
        console.log('Event data:', eventData);
    };

    const collectionDetails = "kianoush"; // provide a valid collectionDetails object
    let crate_collection = await api.createCollection(account, collectionDetails);

    const newAccounta = await api.createAccount();
    const newAccountb = await api.createAccount();
    const newAccountc = await api.createAccount();


    let set_config = await api.setConfig(account, 5, 5);
    console.log(set_config)

    const nftDetails = {
        collectionId: crate_collection.result,
        metadata: "kianoush",
        royalty: 10,
        share_profits: [
            { percentage: 50, owner_address: newAccounta.address },
            { percentage: 30, owner_address: newAccountb.address },
            { percentage: 20, owner_address: newAccountc.address },
        ],
        price: 1000000000000000n,
        end_date: 1000000000000000n,
    };
    let mint_nft = await api.mintNft(account, nftDetails);
    console.log(mint_nft)

    const albumDetails = {
        collectionId: crate_collection.result,
        metadata: "My Album",
        royalty: 10,
        tracks: [
            {
                track_id: null,
                metadata: "Track 1",
                owners: [],
                share_profits: [
                    { percentage: 50, owner_address: newAccounta.address },
                    { percentage: 25, owner_address: newAccountb.address },
                    { percentage: 25, owner_address: newAccountc.address },
                ],
                price: 1,
            },
            {
                track_id: null,
                metadata: "Track 2",
                owners: [],
                share_profits: [
                    { percentage: 50, owner_address: newAccounta.address },
                    { percentage: 25, owner_address: newAccountb.address },
                    { percentage: 25, owner_address: newAccountc.address },
                ],
                price: 1,
            },
        ],
        endDate: 1,
    };
    let mint_album = await api.mintAlbum(account, albumDetails);
    console.log(mint_album)


    let buy_album = await api.buyAlbum(account, Number(mint_album.result.collectionId), Number(mint_album.result.albumId), 1);
    console.log(buy_album)

    const updatedShareProfits = [
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 95, owner_address: newAccounta.address },
    ];

    let update_share_nft = await api.updateShareProfitNft(account, Number(mint_nft.result.collectionId), Number(mint_nft.result.nft_id), updatedShareProfits);
    console.log('up', update_share_nft)

    const updatedShareProfitsAlbum = [
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 1, owner_address: newAccounta.address },
        { percentage: 95, owner_address: newAccounta.address },
    ];

    let update_share_album = await api.updateShareProfitAlbum(account, Number(mint_album.result.collectionId), Number(mint_album.result.albumId), Number(2), updatedShareProfitsAlbum);
    console.log('up', update_share_album)

    let buy_nft = await api.buyNFT(account, Number(mint_nft.result.collectionId), Number(mint_nft.result.nft_id), 1);
    console.log(buy_nft)
})().catch(console.error);

Transfer Token

const hearVerse = require("hear-verse");

async function main() {
  
  const hv = new hearVerse('ws://server-address');
  await hv.connect();

  const newAccount = hv.createAccount();
  console.log('New account:', newAccount);

  // Transfer native tokens example
  const toAddress = '5GJ1p...'; // Replace with the recipient's address
  const amount = 1000000000000; // Replace with the desired transfer amount

  try {
    const result = await hv.transfer(newAccount, toAddress, amount);
    console.log('Transaction successful, included in block hash:', result.blockHash);
  } catch (error) {
    console.error('Transaction failed:', error.message);
  }
}
main().catch(console.error);

In the example above, we added the usage of the transfer function to transfer native tokens. Replace the sample toAddress and amount with your desired values.