3

Is there a way in polkadot js api to be able to get the state of an object after a transaction if it is applied in the future? Is there a way in Substrate to apply a transaction(or its past implementation) to test the result?

My goal is given a current state of an object(account, balance, or any pallet), to apply a transaction as it is in Substrate, without duplicating implementation on js client, to get the resulting state of an object without actually submitting transaction to the blockchain so that we can test the transaction's result. Is there a way to apply an older version of a transaction(if there were past changes) in order to see the difference between current and past results?

Thank you

2 Answers 2

5

The JS API wraps the system_dryRun RPC and makes it accessible on the transaction object.

To access, use the following -

// create a transaction
const tx = api.tx.balances.transfer(...)

// dry-run it (same options as signAndSend)
await tx.dryRun(signingPair, { ...options }, (...) => { ... });

If you have old transactions which are already signed,

// construct a transaction from the actual signed data
const tx = api.tx(0x...extrinsic hex...);

// alternatively construct the tx as above and then
// await tx.signAsync(....) to get it signed

// dry run it
await tx.dryRun(signerPair, '0x...blockHash...');
2

Substrate API Sidecar has a POST endpoint to dry run a extrinsic (transaction):

POST /transaction/dry-run

And in the body of the POST request you add the serialized (and signed) byte array of the transaction.

Moreover, you can check the state of an account with the GET /accounts/ series of endpoints. Check this reference for details about these endpoints.

Also check this link to know how to run Substrate API Sidecar in your local machine and connect it to your local node or any other external node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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