项目作者: filecoin-shipyard

项目描述 :
An API client for Filecoin implemented in Java
高级语言: Java
项目地址: git://github.com/filecoin-shipyard/java-filecoin-api-client.git
创建时间: 2019-08-09T02:47:53Z
项目社区:https://github.com/filecoin-shipyard/java-filecoin-api-client

开源协议:Other

下载


java-filecoin-api-client

Status

This repository is in a frozen state. It is not being maintained or kept in sync with the libraries it depends on. This library was designed for an early version of go-filecoin, which is now known as Venus. Even though work on this repository has been shelved, anyone interested in updating or maintaining this library should express their interest on one Filecoin community conversation mediums: https://github.com/filecoin-project/community#join-the-community.


An API client for Filecoin implemented in Java

Quick Start

At present, this artifact has not been published to Maven central repository, so you should install locally

  1. mvn clean install

For general projects

(1) import dependency in pom.xml

  1. <dependency>
  2. <groupId>org.rockyang</groupId>
  3. <artifactId>filecoin-api-client</artifactId>
  4. <version>0.0.1</version>
  5. </dependency>

(2) initialize Filecoin instance

  1. Filecoin filecoin = new Filecoin("http://127.0.0.1:3453", false);

For SpringBoot projects

(1) import dependency in pom.xml, and you do not need to import filecoin-api-client in additional.

  1. <dependency>
  2. <groupId>org.rockyang</groupId>
  3. <artifactId>filecoin-api-client-spring-boot-starter</artifactId>
  4. <version>0.0.1</version>
  5. </dependency>

(2) set log-debug and api-base-url in application.properties

  1. # switch to open http debug log
  2. filecoin.log-debug=true
  3. # filecoin rpc api base url
  4. filecoin.api-base-url=http://127.0.0.1:3453

(3) use the Filecoin instance by @Autowired or @Resource annotation any where you want to do.

  1. public class FilecoinController {
  2. @Autowired
  3. private Filecoin filecoin;
  4. }

Usage

  1. // create a new addresss
  2. String address = filecoin.newAddress();
  3. // fetch all address of current node
  4. List<String> addresses = filecoin.getAddressList();
  5. // export an address
  6. String address = "t1b3keswmeuk4tipp5egjbk3aoag56g5zd3cle2va";
  7. KeyInfo keyInfo = filecoin.walletExport(address);
  8. // import wallet
  9. String privateKey = "pdHwTOrJXnAGvQ0861k66xRsiT7N3Ms8IGte3nT837E=";
  10. String address = filecoin.walletImport(privateKey);
  11. // get balance
  12. String address = "t1esjjrygs7adcfbjnodbpdjzulzobznnln4tmsxq";
  13. BigDecimal balance = filecoin.getBalance(address);
  14. logger.info(balance);
  15. // send transaction
  16. String from = "t16cgjiwgypve4uup27uk4xgppgd3i4nsldpid6ii";
  17. String to = "t1esjjrygs7adcfbjnodbpdjzulzobznnln4tmsxq";
  18. BigDecimal value = BigDecimal.valueOf(123.456);
  19. BigDecimal gasPrice = BigDecimal.valueOf(0.001);
  20. Integer gasLimit = 300;
  21. String cid = filecoin.sendTransaction(from, to, value, gasPrice, gasLimit);
  22. // get transction status
  23. String cid = "zDPWYqFCtwpgqBEth4wFK53D8Sm9UGxhrL1tueb4RrgFDQLoKC1P";
  24. MessageStatusRes.Message message = filecoin.getTransaction(cid);

document | API

The document is building, if you need it urgently, we provide unit testing for each API.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

The Filecoin Project is dual-licensed under Apache 2.0 and MIT terms: