bdcontract
Go to file
2023-03-18 19:55:44 +08:00
src merge 0.4.0 2023-03-18 15:48:45 +08:00
test chore: build axios-fetch for test 2023-03-18 19:55:44 +08:00
test-node initial commit 2023-03-15 01:15:57 +08:00
.gitignore merge code 0.4.0 2023-03-18 18:43:58 +08:00
DEVELOP.md add develop.md 2023-03-15 10:07:21 +08:00
LICENSE initial commit 2023-03-15 01:15:57 +08:00
package.json chore: build axios-fetch for test 2023-03-18 19:55:44 +08:00
README.md merge 0.4.0 2023-03-18 15:48:45 +08:00
rollup.config.js initial commit 2023-03-15 01:15:57 +08:00
rollup.config.ts chore: build axios-fetch for test 2023-03-18 19:55:44 +08:00
tsconfig.build.json initial commit 2023-03-15 01:15:57 +08:00
tsconfig.json initial commit 2023-03-15 01:15:57 +08:00

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