搭建WeBASE, 请参考快速部署
安装WeBASE完成后,需要将节点信息添加到WeBASE平台中,这样WeBASE才可和节点进行通信。需要添加的信息包含节点信息,生成用户的私钥等。如下图所示:
以HelloWorld.sol为例
pragma solidity ^0.4.2;
contract HelloWorld{
string name;
function HelloWorld(){
name = "Hello, World!";
}
function get()constant returns(string){
return name;
}
function set(string n){
name = n;
}
}
请参考交易接口
从IDE中的输出信息,拷贝合约地址,合约名,方法名等信息,同时获取用户的公钥信息,调用交易接口。 具体代码请参考 HelloWorld范例
- application.yml
transactionUrl: http://127.0.0.1:5002/WeBASE-Front/trans/handle
groupId: 1
userAddress: "0x4f08eac5af5e77b7006d11bee94adba2f721def8"
useAes: true
contract.name: HelloWorld
contract.address: "0xca597170829f4ad5054b618425a56e0be23cbc55"
contract.funcName: set
contract.funcParam: "[\"abc\"]"
contract.contractAbi: "[{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"
- TransactionService.java
@Slf4j
@Data
@Service
public class TransactionService {
@Autowired
private RestTemplate rest;
@Value("${transactionUrl}")
private String url;
@Value("${userAddress}")
private String user;
@Value("${groupId}")
private int groupId;
@Value("${useAes}")
private Boolean useAes;
@Value("${contract.name}")
private String contractName;
@Value("${contract.address}")
private String contractAddress;
@Value("${contract.funcName}")
private String funcName;
@Value("${contract.funcParam}")
private String funcParam;
@Value("${contract.contractAbi}")
private String contractAbi;
public void sendTransaction() {
try {
TransactionParam transParam = new TransactionParam();
transParam.setGroupId(groupId);
transParam.setContractAddress(contractAddress);
transParam.setUseAes(useAes);
transParam.setUser(user);
transParam.setContractName(contractName);
transParam.setFuncName(funcName);
transParam.setFuncParam(JSONArray.parseArray(funcParam));
transParam.setContractAbi(JSONArray.parseArray(contractAbi));
log.info("transaction param:{}", JSON.toJSONString(transParam));
Object rsp = rest.postForObject(url, transParam, Object.class);
String rspStr = "null";
if (Objects.nonNull(rsp)) {
rspStr = JSON.toJSONString(rsp);
}
log.info("transaction result:{}", rspStr);
} catch (Exception ex) {
log.error("fail sendTransaction", ex);
}
System.exit(1);
}
}
应用层发布后,持续发送交易,可在WeBASE管理平台查看数据概览,节点监控,查看交易解析,交易审计等管理功能。