2

I wrote a smart contract and deployed on my private Quorum. I use Web3j to generate java wrapper to call ABIs. For example,

// here is a smart contract function
function getMoney() external payable 
{
    Event_GotMoney(msg.value, now);
}

In my java, if I call like this

contract.getMoney(new BigInteger(100)).send();
// or
// contract.getMoney(new BigInteger(100));

I can always get Event_GotMoney event. However, if I want to call it continuously, like this, (asynchronized)

for(int i=0; i<100; i++)
    contract.getMoney(new BigInteger(100));

I can't get 100 Event_GotMoney events. The interval of the timestamp in the event is 3 or 10 seconds(depends on the frequency of generating blocks). I guess the nonce isn't updated util a block generated. If my guess is correct, how can I call smart contract functions continuously? If not, is it a limitation or something?


Another small question, I use event observable functions provided by Web3j wrapper. It works well to get events, but it updates every 15 seconds. How could I modify the interval?

Any feedback would be appreciate.

0

1 Answer 1

6

I found the solution, please refer, #296

Use FastRawTransactionManager to speed up your transactions. Use RawTransactionManager to shorten the polling interval. If you need both, use the following code,

pollingInterval = 3000; // 3 seconds
FastRawTransactionManager fastRawTxMgr = new FastRawTransactionManager(web3, credentials, new PollingTransactionReceiptProcessor(web3j, pollingInterval, 40));
Contract contract = MyPersonalContract.load(contractAddr, web3, fastRawTxMgr, gasPrice, gasLimit);
2
  • the polling interval would be every 3 seconds according to the code, that is, every 3 seconds you will see the transaction to return txHash ?, and the number 40 for what it works? Apr 17, 2019 at 23:35
  • No, it means polling the txHash every 3 seconds and retry 40 times. If it over 40 times, it will return error.
    – Kimi Wu
    Apr 19, 2019 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.