1.0.26 • Published 5 years ago

schain_sdk v1.0.26

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

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.

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago