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

schain_sdk

v1.0.26

Published

sdk for schain

Downloads

65

Readme

schain-sdk

SChain Javascript SDK, provides a set of wrapper functions that help you accessing your chaincode.

Prerequisite

An API KEY and an APP ID are required while using the SDK. Read the Get started guide to get them.

Install package

npm i schain_sdk

Usage

Import package

const schain = require('schain_sdk');

Initialize

// Replace API_KEY and APP_ID with yours
const API_KEY = '5d5b9cbd55cc6725f82dabba0632fe6e';
const APP_ID = 'app-38b30623-c207-4025-8c80-69df51f822c2';

schain.init(API_KEY, APP_ID)

Simple store template

The SDK provides a set of convenient functions that support the simple store template chaincode.

Set a value

let key = 'key1';
let value = '100';

await schain.set(key, value).then(result => {
    console.log('done');
}).catch(error => {
    console.log(error);
});

Get a value

let key = 'key1';

await schain.get(key).then(value => {
    console.log('value=' + value);
}).catch(error => {
    console.log(error);
});

Delete a value

let key = 'key1';

await schain.delete(key).then(result => {
    console.log(result);
}).catch(error => {
    console.log(error);
});

Custom chaincode

Not only the chaincode template, the SDK also supports your custom chaincode.

With the SDK, you can invoke and query functions defined in your custom chaincode.

Register an user

If your apps need to distinguish user identities, you can register an user by calling register.

let username = 'user01';

await schain.register(username).then(result => {
    console.log('done');
}).catch(error => {
    console.log(error);
});

Invoke a chaincode function

Invoke a chaincode function to update the blockchain ledger data.

// Specify an user identity that is used to invoke the chaincode function.
// A null value is allowed if user identity is not that important for this function.
let username = 'user01';

// The function name to be invoked
let func = 'invoke';

// The arguments to be passed to the function
let args = ['a', 'b', 'c'];

await schain.invokeChainCode(username, func, args).then(result => {
    console.log('done');
}).catch(error => {
    console.log(error);
});

Query a chaincode function

Query blockchain ledger data by querying a chaincode function.

// Specify an user identity that is used to query the chaincode function.
// A null value is allowed if user identity is not that important for this function.
let username = 'user01';

// The function name to be queried
let func = 'query';

// The arguments to be passed to the function
let args = ['a'];

await schain.queryChainCode(username, func, args).then(result => {
    console.log(result);
}).catch(error => {
    console.log(error);
});

License

Copyright 2019 S-Chain Technologies Limited

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.