harmony-one / sdk

Javascript SDK of Harmony protocol.
MIT License
92 stars 43 forks source link

Running concurrent HRC20 token transfers, without an error. #96

Closed trekze closed 3 years ago

trekze commented 3 years ago

Simply, is it possible?

Whenever we attempt to run two token transfers concurrently, using:

   await contract.methods
                .transfer(to, new Unit(amount).asOne().toWei())
                .send({
                    from: from,
                    gasLimit: '250000', //default gaslimit for Hrc20 transaction is 250000
                    gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
                })

One of them fails with an error, usually: transaction failed:replacement transaction underprice

We could build a queuing system of course, but wondering if it's necessary.

Cheers

gupadhyaya commented 3 years ago

passing the nonce to send function should allow for concurrent transfers.

await contract.methods
                .transfer(to, new Unit(amount).asOne().toWei())
                .send({
                    nonce: counter
                    from: from,
                    gasLimit: '250000', //default gaslimit for Hrc20 transaction is 250000
                    gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
                })
trekze commented 3 years ago

Super!

Any chance you could have a look at my other issue?

Thanks in advance.