-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Transaction dependency estimation via provider.estimateTxDependencies is currently done always before a transaction is sent to a node. This causes unnecessary round-trips to the node and strain to the network in cases where this estimation is unnecessary.
Instead of calling it on every call, we should make it an opt-in feature in cases where the user actually needs it. For more info on when this is needed, one can refer to the excellent documentation of fuels-rs on this topic.
Regarding the API, fuels-rs uses method chaining because rust allows for this pattern:
let response = contract_methods
.mint_then_increment_from_contract(called_contract_id, amount, address)
.estimate_tx_dependencies(Some(2))
.await? // <----- this thing right here
.call()
.await?;This API would be great but we'd have to write some questionable Promise-related code to allow it:
let response = await contract_methods
.mint_then_increment_from_contract(called_contract_id, amount, address)
.estimate_tx_dependencies(Some(2))
.call();Due to that, I'm more in favor of making it part of the call params:
const response = await contract_methods
.mint_then_increment_from_contract(called_contract_id, amount, address)
.call({
estimateTxDependencies: 10 // boolean | number indicating how many round trips are allowed
})fuels-rs supports this for single contract calls, multi-calls, as well as script calls. They did it via a trait called TxDependencyExtension.