Skip to content

chinaares/tron_wallet_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

波场(TRON)钱包服务

主要实现了TRON区块链的钱包相关操作

  • 地址创建
  • TRX 转账创建
  • TRC20 转账交易创建
  • TRC10 转账交易创建
  • 交易都是支持memo

如何使用

git clone https://github.com/yanwankun/tron_wallet_server.git

安装需要的依赖

mvn install:install-file -Dfile=wallet-cli-4.2.1.jar -DgroupId=io.tron -DartifactId=wallet-cli -Dversion=4.2.1-SNAPSHOT -Dpackaging=jar -DlocalRepositoryPath=D:\maven\repository
mvn install:install-file -Dfile=tron-protobuf-1.0-SNAPSHOT.jar -DgroupId=org.tron -DartifactId=tron-protobuf -Dversion=1.0-SNAPSHOT -Dpackaging=jar -DlocalRepositoryPath=D:\maven\repository

测试

private static String from = "TY222tTvWPuxEv58bWmSVg6r695BCZveer";
private static String to = "TLLA27KNJuU9EFViiCkruVBTrfwhiyuUYL";
private static String tokenAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; #这个是TRC20_USDT 的合约地址
private static String priKey = ""; # 这里填写你自己的私钥,是上面from地址的私钥

转账TRX

@Test
void testTransferTrx() {
    CreateTransactionParam param ;
    param = CreateTransactionParam.builder()
            .from(from)
            .to(to)
            .amount(100L)
            .currency("TRX")
            .memo("test_add_0001")
            .build();
    BaseResult<CreateTxView> createTxViewBaseResult = tronController.create(param);
    System.out.println("create => " + JSON.toJSONString(createTxViewBaseResult));
    sleep(12);
    SignTransactionParam signTransactionParam = SignTransactionParam.builder()
            .priKey(priKey)
            .unSignTx(createTxViewBaseResult.getData().getUnSignTxStr())
            .build();
    BaseResult<String> signResult = tronController.signTx(signTransactionParam);
    System.out.println("signTx => " + JSON.toJSONString(signResult));
    sleep(12);
    BroadCastTransactionParam broadCastTransactionParam = BroadCastTransactionParam.builder()
            .signStr(signResult.getData())
            .build();
    BaseResult broadCastResult = tronController.broadCast(broadCastTransactionParam);
    System.out.println("broadCast => " + JSON.toJSONString(broadCastResult));
}

转账TRC20

@Test
void testTransferTrc20() {
    CreateTransactionParam param ;
    param = CreateTransactionParam.builder()
            .from(from)
            .to(to)
            .amount(100L)
            .currency("USDT")
            .memo("test_add_0001")
            .tokenAddress(tokenAddress)
            .build();
    BaseResult<CreateTxView> createTxViewBaseResult = tronController.create(param);
    System.out.println("create => " + JSON.toJSONString(createTxViewBaseResult));
    sleep(12);
    SignTransactionParam signTransactionParam = SignTransactionParam.builder()
            .priKey(priKey)
            .unSignTx(createTxViewBaseResult.getData().getUnSignTxStr())
            .build();
    BaseResult<String> signResult = tronController.signTx(signTransactionParam);
    System.out.println("signTx => " + JSON.toJSONString(signResult));
    sleep(12);
    BroadCastTransactionParam broadCastTransactionParam = BroadCastTransactionParam.builder()
            .signStr(signResult.getData())
            .build();
    BaseResult broadCastResult = tronController.broadCast(broadCastTransactionParam);
    System.out.println("broadCast => " + JSON.toJSONString(broadCastResult));

}

转账TRC10

@Test
void testTransferTrc10() {
    CreateTransactionParam param ;
    param = CreateTransactionParam.builder()
            .from(from)
            .to(to)
            .amount(100L)
            .currency("AAMT")
            .memo("test_add_0001")
            .assetName("31303034303731")
            .build();
    BaseResult<CreateTxView> createTxViewBaseResult = tronController.create(param);
    System.out.println("create => " + JSON.toJSONString(createTxViewBaseResult));
    SignTransactionParam signTransactionParam = SignTransactionParam.builder()
            .priKey(priKey)
            .unSignTx(createTxViewBaseResult.getData().getUnSignTxStr())
            .build();
    BaseResult<String> signResult = tronController.signTx(signTransactionParam);
    System.out.println("signTx => " + JSON.toJSONString(signResult));
    BroadCastTransactionParam broadCastTransactionParam = BroadCastTransactionParam.builder()
            .signStr(signResult.getData())
            .build();
    BaseResult broadCastResult = tronController.broadCast(broadCastTransactionParam);
    System.out.println("broadCast => " + JSON.toJSONString(broadCastResult));

}

特别感谢

  • tron-sdk

    我参考和借鉴了很多,解决了我写这个的很多问题

  • wallet-cli

    弄这个真的是要气死人啊,首先我对gradle不是很熟悉,其次我始终没有搞明白为什么他会集成了 spring-cloud-sonsul,还好的是最后也算参考完成了我的代码编写

联系我

  • qq : 1101186635

如果你想请我喝杯可乐,我也不会拒绝的

支付宝收款码 TRON收款码 微信收款码

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages