<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.8.4</version>
</dependency>
public String test(String privateKey,BigInteger gasPrice,BigInteger gasLimit,BigInteger nonce,String contractAddr,BigInteger val,String data){
Credentials credentials = Credentials.create(privateKey);
// String form = credentials.getAddress();
Web3j web3j = Web3j.build(new HttpService("節點URL"))
RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, contractAddr,val, data);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction,56,credentials);
String hexValue = Numeric.toHexString(signedMessage);
//請求發出前得到txHash
String txHash = Hash.sha3(hexValue);
try {
EthSendTransaction ethSendTransaction = client.ethSendRawTransaction(hexValue).send();
//也可在請求發出后通過以下方法獲得txHash
txHash = ethSendTransaction.getTransactionHash();
} catch (IOException e) {
e.printStackTrace();
}
return txHash;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/332151.html
標籤:區塊鏈
下一篇:高頻交易的前世今生
