2022年USDT核心代码
Posted ZeroTeam_麒麟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2022年USDT核心代码相关的知识,希望对你有一定的参考价值。
波场JAVA版
创建参数实体类 TransferRQ
public class TransferRQ
@NotEmpty(message = "私钥不能为空")
private String hexPrivateKey;
@NotEmpty(message = "地址不能为空")
private String ownerAddress;
@NotEmpty(message = "对方地址不能为空")
private String toAddress;
@NotNull(message = "数量不能空")
@Min(value = 1, message = "数量不能小于1")
@Max(value = 99999, message = "数量不能大于99999")
private BigInteger amount;
/** 转账备注 **/
private String memo;
创建交易返回实体类 tradeRS
public class tradeRS
/** txId 交易哈希ID**/
private String txnId;
/** 发起者地址 **/
private String ownerAddress;
/** 对方地址 **/
private String toAddress;
/** 交易数量 **/
private BigInteger amount;
导入依赖的jar
abi-0.3.0.jar
core-0.3.0.jar
utils-0.3.0.jar
grpc-api-1.31.0.jar
grpc-context-1.31.0.jar
grpc-core-1.31.0.jar
grpc-netty-1.31.0.jar
grpc-netty-shaded-1.31.0.jar
grpc-okhttp-1.31.0.jar
grpc-protobuf-1.31.0.jar
grpc-protobuf-lite-1.31.0.jar
grpc-stub-1.31.0.jar
netty-all-4.0.15.Final.jar
perfmark-api-0.19.0.jar
protobuf-java-3.13.0.jar
发起交易方法
/**
* 发起 TRC20 USDT交易
*
* @param transfer
* @return
*/
public tradeRS TRC20Transfer(TransferRQ transfer)
try
log.info("\\t发起USDT交易----->", logPrefix, transfer);
//选择网络
ApiWrapper client = ApiWrapper.ofMainnet(transfer.getHexPrivateKey());
Function trc20Transfer = new Function("transfer",
Arrays.asList(new Address(transfer.getToAddress()),
//数量
new Uint256(transfer.getAmount().multiply(decimal))),
Arrays.asList(new TypeReference<Bool>()
));
String encodedHex = FunctionEncoder.encode(trc20Transfer);
Contract.TriggerSmartContract trigger =
Contract.TriggerSmartContract.newBuilder()
.setOwnerAddress(ApiWrapper.parseAddress(transfer.getOwnerAddress()))
//合约地址
.setContractAddress(ApiWrapper.parseAddress(CS.TRC20_CONTRACT.USDT))
.setData(ApiWrapper.parseHex(encodedHex))
.build();
//发送
Response.TransactionExtention txnExt = client.blockingStub.triggerContract(trigger);
TransactionBuilder signBuilder = new TransactionBuilder(txnExt.getTransaction());
//设置手续费上线否则会失败
signBuilder.setFeeLimit(100000000L);
//备注
signBuilder.setMemo("Api");
Chain.Transaction signedTxn = client.signTransaction(signBuilder.getTransaction());
//进行广播否则txId会跟交易的不一致
String txId = client.broadcastTransaction(signedTxn);
log.info("txn id => " + txId);
Response.TransactionReturn ret = client.blockingStub.broadcastTransaction(signedTxn);
log.info("\\t\\t交易[个USDT到]\\t\\ntxnId=", logPrefix, transfer.getOwnerAddress(), transfer.getAmount(), transfer.getToAddress(), txId);
Assert.isTrue(ret.getResult(), "交易失败");
return new tradeRS().setTxnId(txId).setAmount(transfer.getAmount()).setOwnerAddress(transfer.getOwnerAddress()).setToAddress(transfer.getToAddress());
catch (Exception e)
log.error("转账异常\\t", e.getMessage());
throw new BizException(e.getMessage());
以上是关于2022年USDT核心代码的主要内容,如果未能解决你的问题,请参考以下文章