From 6e8363c12e865ad6346ad81570e8367751fe1a6e Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Wed, 9 Mar 2022 18:09:22 +0800 Subject: [PATCH] add simple readme.md --- README.md | 30 +++++++++++++++++++ .../bdware/client/SmartContractClient.java | 1 + 2 files changed, 31 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a1ffc0 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +1. 通过HTTP协议用: +直接拼接URL参考:https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69 + +使用SDK参考test目录下的SmartContractHttpClientTest.java +```java +//当需要发起签名调用时,使用正确的privateKey和publicKey。 +SmartContractHttpClient client = + new SmartContractHttpClient( + SM2KeyPair.fromJson( + "{\"privateKey\":\"...\",\"publicKey\":\"...\"}"), + IP, + port); + System.out.println(client.executeContractAsString(contractID_or_contractName, operation,arg)); +``` + +2.通过WebSocket调用 +使用SDK参考test目录下的SmartClientTest.java +```java +SmartContractClient client = new SmartContractClient("ws://ip:port/SCIDE/SCExecutor") ; +//如果需要指定key,也可传入key参数。 +//SM2KeyPair key = SM2KeyPair.fromJson("json格式的密钥对"); +//client = new SmartContractClient("...",key); +client.waitForConnect(); +client.login(); +ContractRequest cr = new ContractRequest(); +cr.setContractID("xxx"); +cr.setAction("xxx"); +cr.setArg("xxx"); +JsonObject result = testClient.executeContractSync(cr); +``` \ No newline at end of file diff --git a/src/main/sdk/org/bdware/client/SmartContractClient.java b/src/main/sdk/org/bdware/client/SmartContractClient.java index 89cae0f..5c898ae 100644 --- a/src/main/sdk/org/bdware/client/SmartContractClient.java +++ b/src/main/sdk/org/bdware/client/SmartContractClient.java @@ -28,6 +28,7 @@ public class SmartContractClient extends SmartContractHandler { SM2KeyPair keyPair; public SmartContractClient(String uri) { + this(uri, SM2Util.generateSM2KeyPair(null)); }