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

dcorejs-lib

v1.6.2

Published

Low level javascript library for Decent blockchain

Downloads

28

Readme

dcorejs-lib

This library is combined forks of graphenejs-lib and graphenejs-ws.

The library was created as a combination of forks of graphenejs-lib and graphenejs-ws with necessary corrections. Can be used to construct, sign and broadcast transactions in JavaScript, and to easily obtain data from the blockchain via public APIs.

npm version npm downloads

Setup

To obtain the library use npm:

npm install dcorejs-lib

Usage

The following examples will provide you basics of dcorejs-lib library usage, like is manipulation and doing fetches of DCore blockchain objects.

Initialization

Moreover, it includes connection to DCore daemon APIs.

    var {Apis, ChainConfig} = require('dcorejs-lib');
    var dcoreWsAddress = 'wss://dcore.address.com';
    
    ChainConfig.networks.decent = {
        chainId: 'your_dcore_chain_id'
    };
    
    Apis.instance(dcoreWsAddress, true).init_promise
        .then(result => {
            // now connected to DCore daemon, can run some commands
        })
        .catch(err => {
            // error connecting to DCore daemon ws interface
        });

Chain

The module provides utility methods which handles DCore blockchain objects.

    var {Apis, ChainStore, FetchChain} = require('dcorejs-lib');
    
    Apis.instance().init_promise
        .then(res => {
            ChainStore.init()
                .then(() => {
                    FetchChain('getAccount', '1.2.30')
                        .then(res => {
                            // object successfully fetched, process DCore network object
                        })
                        .catch(err => {
                            // error fetching object from DCore blockchain
                        });
                })
                .catch(err => {
                    // error initializing chain store
                });
        })
        .catch(err => {
            // error connecting to DCore daemon ws interface
        });

Private keys

Generate a new private key from a seed (e.g. a brainkey).

    var {PrivateKey, key} = require("dcorejs-lib");
    
    let seed = "THIS IS A TERRIBLE BRAINKEY SEED WORD SEQUENCE";
    let pkey = PrivateKey.fromSeed( key.normalize_brainKey(seed) );
    
    console.log("\nPrivate key:", pkey.toWif());
    console.log("Public key :", pkey.toPublicKey().toString(), "\n");

Transactions

Following example show the way of broadcasting transfer operation transaction into DCore network.

    var {Apis, TransactionHelper, ChainStore, FetchChain, Aes, TransactionBuilder} = require('dcorejs-lib');

    var amount = 0.11;
    var fromAccountId = 'sender_account_name';
    var toAccountId = 'receiver_account_name';
    var memoMessage = 'some memo for receiver';
    
    Apis.instance().init_promise
        .then(res => {
            ChainStore.init()
                .then(() => {
                   Promise.all([
                       FetchChain('getAccount', fromAccountId),
                       FetchChain('getAccount', toAccountId),
                       FetchChain('getAsset', 'DCT'),
                   ])
                   .then(result => {
                       var [fromAccount, toAccount, amountAsset] = result;
                       
                       var privateKey = fromAccount.get('owner').get('key_auths').get(0).get(0);
                       var senderMemoKey = fromAccount.get('options').get('memo_key');
                       var receiverMemoKey = toAccount.get('options').get('memo_key');
                       var nonce = TransactionHelper.unique_nonce_uint64();
                       
                       var memo = {
                           from: senderMemoKey,
                           to: receiverMemoKey,
                           nonce: nonce,
                           message: Aes.encrypt_with_checksum(privateKey, receiverMemoKey, nonce, memoMessage),
                       };
                       
                       var tb = new TransactionBuilder();
                       tb.add_type_operation('transfer', {
                           fee: {
                               amount: 0,
                               asset_id: amountAsset.get('id')
                           },
                           from: fromAccount.get('id'),
                           to: toAccount.get('id'),
                           amount: {
                               amount: amount, 
                               asset_id: amountAsset.get('id')
                           },
                           memo: memo
                       });
                       tb.set_required_fees()
                        .then(() => {
                            tr.add_signer(privateKey, privateKey.toPublicKey().toPublicKeyString());
                            tr.broadcast()
                                .then(() => {
                                    // transaction successfully broadcasted to DCore network
                                })
                                .catch(err => {
                                    // error broadcasting transaction
                                });
                        })
                        .catch(err => {
                            // error setting transaction fees
                        });
                   });
                });
        })
        .catch(err => {
            // error connecting to DCore daemon ws interface
        });