- contract 应用合约,sol文件
- fiscobcos-dev 链证书、机构证书、机构私钥、账户
- application-dev.yml
encrypt-type: # 0:普通, 1:国密
encrypt-type: 0 #集群使用的加密类型
group-channel-connections-config:
caCert: classpath:fiscobcos-${spring.profiles.active}/ca.crt #链证书
sslCert: classpath:fiscobcos-${spring.profiles.active}/sdk.crt #机构证书
sslKey: classpath:fiscobcos-${spring.profiles.active}/sdk.key #机构私钥
gmCaCert: classpath:fiscobcos-${spring.profiles.active}/gmca.crt #集群为国密版,则需要配置
gmEnSslCert: classpath:fiscobcos-${spring.profiles.active}/gmensdk.crt
gmEnSslKey: classpath:fiscobcos-${spring.profiles.active}/gmensdk.key
gmSslCert: classpath:fiscobcos-${spring.profiles.active}/gmsdk.crt
gmSslKey: classpath:fiscobcos-${spring.profiles.active}/gmsdk.key
all-channel-connections:
- group-id: 1 # sdk实际连接的群组
connections-str:
# 若节点小于v2.3.0版本,查看配置项listen_ip:channel_listen_port
- 192.168.160.136:20200
- 192.168.160.136:20201
#- group-id: 2
#connections-str:
#- 192.168.160.130:20200
#- 192.168.160.130:20201
#- 192.168.160.135:20202
#- 192.168.160.135:20203
channel-service:
group-id: 1 # sdk实际连接的群组
agency-name: fisco # 机构名称
accounts:
pem-file: classpath:fiscobcos-${spring.profiles.active}/0x9ff96dcf17f27ddd643c23bc1236733aa92a1f20.pem #账户
contract-address:
kVPerson: "0x3cc40ecd5000f58c3458fef29b91114bd5e18da3"#合约地址
- pom.xml 引用fisco-bcos-web3sdk的2.6.1版本
deploy KVPerson
transaction hash: 0x72908963644b7e897bf03d0a9ddb9f76428f5b1684aee89eb251d0adf15bdb75
contract address: 0x3cc40ecd5000f58c3458fef29b91114bd5e18da3
把合约地址复制到项目的application-dev.yml配置文件里,通过合约地址来加载合约,获取合约对象。
使用web3sdk api将合约转换成java文件。执行SolidityGeneratorTest的compileSolFilesToJava(),在com.fish1208.temp包下生成java文件。
将转换后的java文件复制到项目com.fish1208.contract包里
通过application-dev.yml配置文件的accounts项,获取签名,Credentials对象
通过application-dev.yml配置文件的group-channel-connections-config项,获取群组连接信息
通过application-dev.yml配置文件的channel-service项,获取Service对象
获取web3j对象
通过application-dev.yml配置文件的contract-address得到合约地址,用来加载合约,获取合约对象
调用合约的set、get方法,进行数据上链、链上数据查询。
http://127.0.0.1:7022/contract/person/set
请求
POST /contract/person/set HTTP/1.1
Content-Type: application/json
{
"id":"3",
"name":"成功",
"age":1000,
"sex":"女"
}
http://127.0.0.1:7022/contract/person/get?id=3 请求
GET /contract/person/get HTTP/1.1
id=3