波场官方trident-java文档
m1 mac Android protobuf 遇到的问题
tron中文文档
trc20离线签名的demo,有trxdent-java,就不需要这个了,使用http的方式可以看看
trc20离线签名的demo,有trxdent-java,就不需要这个了,使用http的方式可以看看,另外一个demo
要继续学习tron可以看看
打包依赖
下载源文件trident-java
这里选择main
分支
进入trident-java文件夹,可以看到有build.gradle,如果是mac系统,修改一下依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| protoc { artifact = 'com.google.protobuf:protoc:3.12.0' artifact = 'com.google.protobuf:protoc:3.12.0:osx-x86_64' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.31.0' artifact = 'io.grpc:protoc-gen-grpc-java:1.31.0:osx-x86_64' } }
|
IDEA打包
打包之后,在每个子模块的build/libs/xxx-jar
下面的操作就可以跟着开发文档了,创建项目
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <dependency> <groupId>org.tron.trident</groupId> <artifactId>abi</artifactId> <version>0.8.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/jar/abi-0.8.0.jar</systemPath> </dependency> <dependency> <groupId>org.tron.trident</groupId> <artifactId>utils</artifactId> <version>0.8.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/jar/utils-0.8.0.jar</systemPath> </dependency> <dependency> <groupId>org.tron.trident</groupId> <artifactId>core</artifactId> <version>0.8.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/jar/core-0.8.0.jar</systemPath> </dependency>
<dependency> <groupId>io.grpc</groupId> <artifactId>grpc-all</artifactId> <version>1.48.1</version> </dependency>
|
查询余额的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public static String privateKey = "私钥"; public static String apiKey = "apiKey"; @Test public void getCount() { KeyPair keyPair = new KeyPair(privateKey); System.out.println(keyPair.toHexAddress()); ApiWrapper wrapper = ApiWrapper.ofMainnet(privateKey,apiKey); Account account = wrapper.getAccount("账户地址"); System.out.println(account.getBalance()); System.out.println(account.getCreateTime()); }
|
转账示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static String transferTrc(String fromAddress, String toAddress, String amount, String contractAddress, String privateKey) { ApiWrapper wrapper = ApiWrapper.ofNile(privateKey); String ret = ""; try { Contract contract = wrapper.getContract(contractAddress); Trc20Contract token = new Trc20Contract(contract, fromAddress, wrapper); BigInteger sunAmountValue = Convert.toSun(amount, Convert.Unit.TRX).toBigInteger(); long maxTrx = Convert.toSun("17", Convert.Unit.TRX).longValue(); ret = token.transfer(toAddress, sunAmountValue.longValue(), 0, "", maxTrx); System.out.println("哈希:" + ret); } catch (Exception e) { System.out.println("转移失败:" + e.getMessage().toString()); } finally { wrapper.close(); } return ret; }
|