mirror of
https://gitee.com/BDWare/sdk-java
synced 2025-01-09 17:34:19 +00:00
30 lines
1.2 KiB
Markdown
30 lines
1.2 KiB
Markdown
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);
|
||
``` |