How to obtain a stable encoding of emitted events from a smart contract?

I have a smart contract which emits events when these events are later fetched from the chain:

pub struct MissionReady {
    owner: AccountId,
    operator: AccountId,
/// Mission finished successfully
pub struct MissionAccomplished {}
/// Mission is deployed on the target fleet as claimed by the network operator
pub struct MissionDeployed {}

they are scale encoded respectively as

[0, 178, 156, 14, 4, 92, 150, 156, 193, 7, 172, 3, 90, 148, 68, 118, 151, 188, 182, 196 ...]

which looks like they are stored in an enum internally.

This encoding changes if the order in the source code is changed.

The generated metadata in the .contract file can be read with a shell command like this:

   cat ./target/ink/$i/$i.contract  | jq '{"V3"}[]."spec"."events"'

But this will only detect changes, not prevent them, is there a way to fixate the encoding to keep the binary interface while recompiling the contract?

  • what do you mean "scale-encoded events"? What exactly do you scale-encode in the ABI? Commented May 4, 2023 at 12:11

1 Answer 1


Currently there is no way to make the encoding independent of the ordering. As you say a internal enum is generated with the event structs as variants and they are just added in the order they appear.

However there is currently a WIP to update the event definition syntax, to make events independent of contract definitions. See https://github.com/paritytech/ink/pull/1243.

This will require events to be defined as enums, and they would maintain their encoding regardless of the order they are defined in.

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.