2

I want to send transactions asynchronously (in parallel) with Taquito. For payments, this works well with a counter (see also https://github.com/ecadlabs/taquito/compare/allow-to-explicitly-set-counter#diff-e58e08dcf2494864df78d3ffeed46f44R137), however, it seems that for contract methods setting a counter has no effect. Can anyone confirm / disagree? Since payments are also somehow contract methods, I was quite surprised that it did not work.

0

I am not sure about what you mean with "counter"? The Github link you provided is for a different branch of Taquito and as of today, I couldn't find in the official documentation any "counter" property in the parameters object for transactions.
Payments are not contract methods because implicit accounts don't have methods and contracts receiving payments behave like implicit accounts (so no method involved).
If you want to send multiple transactions in parallel, what about using "Promise.all"? For example:

const promise1 = await contract.methods.transfer(params1).send();
const promise2 = await contract.methods.transfer(params2).send();
const [op1, op2] = await Promise.all([promise1, promise2]);
| improve this answer | |
  • Thanks a lot for your comment. I send payments via let result = await tezos.contract.transfer({to: receiver, amount: 1000, fee: 10000, counter: Math.floor(Math.random() * 1000000000)}). I can easily send tens or even hundreds of transactions in parallel, and they will all succeed. When I do not specify a counter at all, all but very few fail with an error stating that the respective counter has already been used. I'm gonna try your suggestion as soon as possible. – Quantenspringer May 30 at 22:35
  • I am still not sure about why you use a counter property on the transfer parameters. Taquito doc doesn't mention it as a built-in feature (Taquito doc). Even so, why using a random number? If you use the counter to count the transactions, why not setting it to zero before incrementing it after each resolved transaction? Math.random is pseudo-random and you may get the same number twice with enough transactions. – Claude Barde May 31 at 8:44
  • When I tested without a counter, I was not able to send transactions in parallel, and with a counter, it worked. =) I want to send transactions at high frequency (>100 tx per second), so I cannot be sure that the order in which I send the transactions from taquito to the tezos-client is the same order in which they are received. Also, I use parallelization in several threads to improve the maximum request sending rate, so I found a random counter easier to implement than a deterministic one. The probability of a collision is small enough for me to ignore it (I only do benchmarking no app). – Quantenspringer May 31 at 10:42
  • OK, I understand now what you are trying to do, I am still unsure about how the counter property works with the transfer parameters object... What about creating a batch of transactions that you send all at once? Taquito allows to create a batch of transactions that are signed and sent in one go. You can even mix tezzies transfers and calls to contract methods! – Claude Barde May 31 at 16:14
  • Thanks a lot for this suggestion! This certainly allows me to increase the load on the system considerably. However, sending parallel requests is still more desirable for benchmarking because it allows to fine-tune the request rate while with batches I can only send new requests when the old ones have been operated. – Quantenspringer Jun 3 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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