'Can't call smart contract functions which require gas fees
The below code interacts with a smart contract and requires gas fees. The problem is that the transaction is failing. It's probably a beginner error I'm making. Because my other functions are working fine. I'm talking about the ones that don't make changes to the contract. I have posted the code and the logs. If something important is missing, just comment on it and I'll add it.
Code -
fun test() {
val function = Function(
functionRegisterVote,
listOf<Type<*>>(Uint256(3)),
emptyList()
)
val txData = FunctionEncoder.encode(function)
val txManager = RawTransactionManager(web3j, Credentials.create(USER_PRIVATE_KEY))
//Error thrown at below line
val txHash = txManager.sendTransaction(
this.requestCurrentGasPrice(), DefaultGasProvider.GAS_LIMIT, CONTRACT_ADDRESS, txData,
BigInteger.ZERO
).transactionHash
val receiptProcessor = PollingTransactionReceiptProcessor(
web3j, TransactionManager.DEFAULT_POLLING_FREQUENCY,
TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH
)
val txReceipt = receiptProcessor.waitForTransactionReceipt(txHash)
Log.d(TAG, "transaction receipt = \ngas used = ${txReceipt.gasUsed}")
}
Log -
2022-03-23 19:57:16.771 27224-27374/com.kenetic.blockchainvs W/System.err: org.web3j.protocol.exceptions.ClientConnectionException: Invalid response received: 403; {"jsonrpc":"2.0","id":1,"error":{"code":-32002,"message":"rejected due to project ID settings"}}
2022-03-23 19:57:16.773 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.protocol.http.HttpService.performIO(HttpService.java:178)
2022-03-23 19:57:16.774 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.protocol.Service.send(Service.java:48)
2022-03-23 19:57:16.774 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.protocol.core.Request.send(Request.java:87)
2022-03-23 19:57:16.774 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.tx.RawTransactionManager.getNonce(RawTransactionManager.java:97)
2022-03-23 19:57:16.775 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.tx.RawTransactionManager.sendTransaction(RawTransactionManager.java:120)
2022-03-23 19:57:16.775 27224-27374/com.kenetic.blockchainvs W/System.err: at org.web3j.tx.TransactionManager.sendTransaction(TransactionManager.java:125)
2022-03-23 19:57:16.775 27224-27374/com.kenetic.blockchainvs W/System.err: at com.kenetic.blockchainvs.block_connector.contract.contract_interface.VoteContractAccessor.test(VoteContractAccessor.kt:127)
2022-03-23 19:57:16.775 27224-27374/com.kenetic.blockchainvs W/System.err: at com.kenetic.blockchainvs.block_connector.contract.contract_interface.VoteContractDelegate.testingFunction(VoteContractDelegate.kt:114)
2022-03-23 19:57:16.776 27224-27374/com.kenetic.blockchainvs W/System.err: at com.kenetic.blockchainvs.ui.ContractScreenFragment$applyBinding$1$6$1.invokeSuspend(ContractScreenFragment.kt:112)
2022-03-23 19:57:16.776 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-03-23 19:57:16.776 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2022-03-23 19:57:16.777 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
2022-03-23 19:57:16.777 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
2022-03-23 19:57:16.778 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
2022-03-23 19:57:16.778 27224-27374/com.kenetic.blockchainvs W/System.err: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
