How does a user initiate more than one item per second?

How does a user initiate more than one item per second?

I found that when sending, such as calling transfer, a transaction can only be completed in about three seconds. If a user wants to send to 10 accounts within one second, how should he do it?

If you need the transaction to settle within one second you should be using state channels.

If you just want to send 10 transactions at the same time you can do that - but it depends on the configuration of the mempool you are talking to, I think the standard configuration is to only allow 5 unconfirmed transactions per user?!

Or, you could use a spend-to-many contract, i.e. a contract to which you send a list of recipients (and amounts) and all the tokens and then the contract distribute the tokens in a single transaction.

2 Likes

Ok, I see. Thank you
If the utility contract calls the send method, what is the maximum number of strokes supported?

Sorry, ‘strokes’ means nothing in this context, I think the real meaning got lost in translation.

1 Like

I mean this

The maximum number of times a contract is supported
Chain.spend

You will probably be limited by the number of addresses you can get in there, and also you need to pay gas for each spend. You shouldn’t have a problem doing 50-100 of them at least.

1 Like

@Baixin.chain
If you are using the JS SDK then you can send to multiple accounts at the same time but the SDK won’t help you with that as it is currently stateless.
When doing

await sdk.trasferValue(...)
await skd.trasferValue(...)

Spends get serialized and this is not what you want

sdk.trasferValue(...)
skd.trasferValue(...)

Looks like it might work but the sdk is bugged and those transactions will have the same nonce :frowning:
The proper code for sending multiple TX’s at the same time is:

                f = (nonce) => {
                    try {
                        console.log(nonce)
                        sdk.transferFunds(0.4, left, {waitMined: false, nonce: nonce, verify: false})
                    } catch(e) {
                        console.log("Transfer left ", k, " failed :(", e)
                    }
                    try {
                        sdk.transferFunds(0.4, right, {waitMined: false, nonce: nonce+1, verify: false})
                    } catch(e) {
                        console.log("Transfer right ", k, " failed :(", e)
                    }
                }
                sdk.getAccountNonce(accounts[id].publicKey).then(f).catch((e) => {return 0})

Until the js sdk fixes the nonce handling feel free to use the above snippet.

Ok, are you saying that if the value of nonce is guaranteed to be different it can be sent multiple times at the same time?

You can create as many TX’s in the sdk as you want, but you need to ensure that the nonces are sequential. One more thing - the JS SDK is checking the nonce before pushing a TX to the mempool which is a PITA, as the validation has the same bug with the nonce as TX creation. This is why you also need to pass the “verify: false” option to disable it.

Well, I’m still learning golang-sdk.Js-SDK, but the general principle should be the same, as long as Nonces is continuous.