使用波場進(jìn)行 轉(zhuǎn)賬、查詢 java demo
otc、ctc。。。可用文章來源地址http://www.zghlxwxcb.cn/news/detail-716432.html
1.轉(zhuǎn)帳usdt
/**
* 轉(zhuǎn)賬
* @param fromAddress 來源地址
* @param fromHexPrivateKey 來源密鑰
* @param toAddress 對方地址
* @param amount 數(shù)量
* @return 區(qū)塊鏈交易id
*/
public static String transferUSDT(String fromAddress, String fromHexPrivateKey, String toAddress, BigInteger amount) {
ApiWrapper client = getApiWrapper(fromHexPrivateKey);
Function transfer =
new Function(
"transfer",
Arrays.asList(new Address(toAddress), new Uint256(amount)),
Arrays.asList(new TypeReference<Bool>() {}));
TransactionBuilder builder =
client.triggerCall(fromAddress, TRC20_USDT_CONTRACT_ADDR, transfer);
builder.setFeeLimit(50000000);
Chain.Transaction transaction = client.signTransaction(builder.getTransaction());
String txid = client.broadcastTransaction(transaction);
client.close();
return txid;
}
2.轉(zhuǎn)帳 trx
/**
* 轉(zhuǎn)賬TRX
* @param fromAddress 來源地址
* @param fromHexPrivateKey 來源 秘鑰
* @param toAddress 目標(biāo)地址
* @param amount 數(shù)量
* @return
* @throws IllegalException
*/
public static String transferTRX( String fromAddress, String fromHexPrivateKey, String toAddress, long amount)
throws IllegalException {
ApiWrapper client = getApiWrapper(fromHexPrivateKey);
Response.TransactionExtention transactionExtention =
client.transfer(fromAddress, toAddress, amount);
Chain.Transaction transaction = client.signTransaction(transactionExtention);
String txid = client.broadcastTransaction(transaction);
client.close();
return txid;
}
3.查詢交易狀態(tài)
/**
* 查詢交易狀態(tài)
*
* @param txid
* @return
* @throws IllegalException
*/
public String getTransactionStatusById(String txid) throws IllegalException {
ApiWrapper client = getApiWrapper(tronServiceConfig.getHexPrivateKey());
Chain.Transaction getTransaction = client.getTransactionById(txid);
return getTransaction.getRet(0).getContractRet().name();
}
文章來源:http://www.zghlxwxcb.cn/news/detail-716432.html
到了這里,關(guān)于玩轉(zhuǎn)區(qū)塊鏈-java TRC20USDT 轉(zhuǎn)賬實(shí)踐的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!