2

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.

1
  • Do you have some details on how listening for events on the RPC is happening? Via polkadot-js/api or some other library (subxt, etc.)?
    – cmichi
    Commented Mar 15, 2023 at 7:07

2 Answers 2

2

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>,
},

Source: https://github.com/paritytech/substrate/blob/8f0b0f69e79c0dcf1487b9858792439c35a1d4cd/frame/contracts/src/lib.rs#L770

2

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;

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.