So lets say I have an unsigned transaction. Is there any way I can simulate the transaction without actually sending it to the chain to see if the transaction will fail or if it will be succesfull? Basically something like estimateGas
on EVM chains.
2 Answers
you can try validate_transaction by calling into the runtime api using the client that you can get handle from outer node
or
from https://polkadot.js.org/apps/#/explorer -> developer -> Runtime calls -> taggedTransactionQueue -> validate_transaction .
-
-
@TadejVengust yes, what didn't you understood with my answer regarding using polkadotjs? May 16 at 10:08
-
By polkadot js I ment polkadot SDK so progamatically via javascript. May 16 at 10:12
-
1@TadejVengust polkadot.js.org/docs/substrate/runtime#taggedtransactionqueue May 16 at 10:20
-
I tried to implement this but it don't quite understand the parameters. This expects 3 parameters which are: - source (local, inBlock, external) - tx - blockHash I want to verify if a transaction will be successful or not. Don't understand why I would need to provide a block hash? Can't find any docs or examples of the usage. Can you provide some? Jul 6 at 9:10
You can use an RPC call to Dry run an extrinsic at a given block. You can construct this with PolkadotJS very easily with tx.dryRun
, see an example here: https://substrate.stackexchange.com/a/2913/2762
However this is an unsafe RPC call and not all the nodes has it activated, if you are running your own node you can activate it with a flag: Unsafe RPC calls?
You can use Sidecar too that exposes an endpoint to dry run a extrinsic.