Our substrate-based smart contract emits an event, which we're listening for via some RPCs. However, we're unable to confirm if the event is genuinely originating from our smart contract. Therefore, we're seeking guidance on how to authenticate the event's legitimacy in relation to our smart contract.
2 Answers
The ContractEmitted
event has the account id of the contract which emitted the event:
/// A custom event emitted by the contract.
ContractEmitted {
/// The contract that emitted the event.
contract: T::AccountId,
/// Data supplied by the contract. Metadata generated during contract compilation
/// is needed to decode it.
data: Vec<u8>,
},
To answer this question in the best possible way you would have to provide more details on which library/tool you are using to listen for events. Ideally with example code.
Generally though the answer is: Any library that I'm aware of does this if you‘re the one issuing the contract invocation.
For polkadot-js/api-contracts
see here: https://polkadot.js.org/docs/api-contract/start/contract.tx/#events.
For subxt
, example code like this will give you the events after submitting an extrinsic:
let tx_events = self
.api
.call(
sp_runtime::MultiAddress::Id(message.account_id().clone()),
value,
dry_run.exec_result.gas_required,
storage_deposit_limit,
message.exec_input().to_vec(),
signer,
)
.await;
polkadot-js/api
or some other library (subxt
, etc.)?