Private-Blockchain
web3j:EthSendTransaction.sendTransaction() 正在拋出“錯誤處理事務請求:無效參數:無效格式”
我正在嘗試使用org.web3j.protocol.core.methods.response.EthSendTransaction庫中的**EthSendTransaction.sendTransaction()**方法將交易發送到地址:0xDD210….
交易包含數據但沒有任何價值(我不必發送資金)。我正在使用專用網路(本地主機:8545)
語法是:
EthSendTransaction transactionResponse = transactionManager.sendTransaction(220000000, 43000, "0xDD210......", hashedData.toString(), BigInteger.valueOf(0)); String transactionHash = transactionResponse.getTransactionHash();
transactionHash 的值為空。
if (transactionResponse.hasError()) { logger.info("in error block"); throw new RuntimeException( "Error processing transaction request: " + transactionResponse.getError().getMessage());
在執行時,程式碼給出
“處理交易請求時出錯:參數無效:十六進制無效。”
有誰知道這個問題的解決方案?
你有沒有嘗試過這樣的事情:
Transaction transaction = Transaction.createFunctionCallTransaction("FROM_ADDRESS", nonce, gasprice, gaslimit, "TO_ADDRESS", encodedData); EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get(); transactionHash = transactionResponse.getTransactionHash();
(你能分享更多你的程式碼嗎,比如你的智能合約中的方法,你如何初始化 transactionManager 以及你如何獲得 hashedData?)
我通常這樣做
Credentials credentials = WalletUtils.loadCredentials("Your PASSWORD", "Your Wallet-File-Location"); // Get Nonce EthGetTransactionCount ethGetTransactionCount = web3j .ethGetTransactionCount(credentials.getAddress(), DefaultBlockParameterName.LATEST).send(); BigInteger nonce = ethGetTransactionCount.getTransactionCount(); RawTransaction rawTransaction = RawTransaction .createTransaction(nonce, "Your GASPRICE", "Your GASLIMIT", "Your Contract-Address", "Your encodedFunction"); // Sign the Transaction byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); String hexValue = Numeric.toHexString(signedMessage); EthSendTransaction transactionResponse = web3j .ethSendRawTransaction(hexValue ).sendAsync().get();
當然,使用 RawTransaction 您應該簽署交易並設置隨機數(我認為交易管理器會為您完成)