Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I inspect the flags from an RPC call using polkadot-js api? #4389

Closed
forgetso opened this issue Dec 24, 2021 · 8 comments
Closed

How do I inspect the flags from an RPC call using polkadot-js api? #4389

forgetso opened this issue Dec 24, 2021 · 8 comments
Labels
stale Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@forgetso
Copy link

Hi, in the docs it states for ContractReverted:

   * The contract ran to completion but decided to revert its storage changes.
   * Please note that this error is only returned from extrinsics. When called directly
   * or via RPC an `Ok` will be returned. In this case the caller needs to inspect the flags
   * to determine whether a reversion has taken place.

Can these flags currently be viewed using polkadot-js api or is it waiting on this? When I call my contract function that should be reverted there are no flags in the ISubmittableResult.

@jacogr
Copy link
Member

jacogr commented Dec 24, 2021

I have no idea about the contract results/flags as stated, have not delved into the newest contract interfaces/RPCs for quite some time. It is quite possibly related to the above. (Quickly took a peek and it indeed seems very much api related as opposed to UI related where it was logged)

@jacogr
Copy link
Member

jacogr commented Dec 26, 2021

I did a bit of digging, where the flags do come through is on the abi.query.<mesage>(...) calls, i.e. the result, if isOk has the flags. so something like -

const { result } = await abi.query.something(123);

if (result.isOk) {
  const { flags } = result.asOk;

  console.log(flags.toNumber());
}

They don't appear on abi.tx.<message> since the events returned, which is the only results from extrinsics, don't contain them. Or at least cannot see any flags in the current events for contracts - https://polkadot.js.org/docs/substrate/events#contracts

@jacogr jacogr added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Dec 26, 2021
@forgetso
Copy link
Author

Thanks for the quick response. That's great I can get them from query.

I should have provided a bit more info. ContractReverted is an error and does not appear in events. It states in the substrate docs that this error contains flags. Does the ContractReverted error propagate through to polkadot-js with flags?

@jacogr
Copy link
Member

jacogr commented Dec 31, 2021

dispatchError always has the errors returned by the transaction. If you can see the details in e.g. the apps UI explorer, the same info is passed through.

@jacogr
Copy link
Member

jacogr commented Dec 31, 2021

Please read the docs carefully, https://polkadot.js.org/docs/substrate/errors#contractreverted , it states -

"The contract ran to completion but decided to revert its storage changes."

Why it occurs ^^^

"Please note that this error is only returned from extrinsics."

Error is returned from extrinsics only ^^

"When called directly or via RPC an Ok will be returned."

RPC behaves different, e.g. always returns Ok, no error.

"In this case the caller needs to inspect the flags to determine whether a reversion has taken place."

The above applies to the last case, when called via RPC. (No flags in extrinsics)

@forgetso
Copy link
Author

Thanks, I think I understand. polkadotjs calls substrate via RPC and is therefore only ever given an Ok and has no details of any errors.

@polkadot-js-bot
Copy link

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stale Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
None yet
Development

No branches or pull requests

3 participants