# BDContract SDK BDContract SDK for Node.js and browsers. ## Install `npm install @bdware/bdcontract-sdk` ```typescript import { WsClient } from '@bdware/bdcontract-sdk' import { sm2 } from 'sm-crypto' const client = new WsClient( url, (ev) => { console.log(JSON.stringify(ev)) }, (ev, ws) => { console.log(ev.data) }, sm2.generateKeyPairHex(), ) ``` To use with plain HTML and JavaScript, include [dist/bdcontract-sdk.umd.js](dist/bdcontract-sdk.umd.js) (example from [test/index.html](test/index.html)): ```HTML ``` ## Usage ```javascript // Approach 1: const wssocket = new WsSocket(url, wsHandler) // Approach 2: function print(string) { document.write(string + '\n\n') } const url = 'ws://021.node.internetapi.cn:21030/SCIDE/SCExecutor' const client = new bdcontract.WsClient( url, (ev) => { console.log(JSON.stringify(ev)) }, (ev, ws) => { console.log(ev.data) }, ) setTimeout(async () => { const status = client.status() console.log(status) try { let data = await client.executeContract( 'AnnotationExample0608', 'main', 'abacd', ) print(JSON.stringify(data)) } catch (data) { print(JSON.stringify(data)) } }, 1000) // Wait for session receival const session = await client.sessionReceived() // Login and wait (will wait if session not yet received) const success = await client.login() async function anotherPlace() { // In another place, wait for login to complete const success = await client.Loggedin() }() ```