@bdware/bdcontract-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.4.0-beta • Public • Published

BDContract SDK

BDContract SDK for Node.js and browsers.

Install

npm install @bdware/bdcontract-sdk

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 (example from test/index.html):

<script type="text/javascript" src="./sm2.js"></script>
<script type="text/javascript" src="./cryptico.iife.js"></script>
<script type="text/javascript" src="../dist/bdcontract-sdk.iife.js"></script>

Usage

// 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()
}()

Package Sidebar

Install

npm i @bdware/bdcontract-sdk

Weekly Downloads

1

Version

0.4.0-beta

License

MIT

Unpacked Size

180 kB

Total Files

8

Last publish

Collaborators

  • caihuaqian
  • nex