Search code examples
rustrust-cargosubstrate

How use hex::encode in Substrate offchain worker?


I'm calling hex::encode from offchain worker, but compilation fails with:

    state.serialize_field("account_id", &hex::encode( self.account_id.encode().as_slice() ) )?;
      |                                       ^^^^^^ not found in `hex`

My Cargo.toml contains:

[features]
default = ['std']
std = [
    ...
    'hex/std'
]

[dependencies]
hex = { version='0.4.3', default-features=false }

How to fix this?


Solution

  • Adding the "alloc" feature to Cargo.toml solved the problem:

    hex = { version='0.4.3', default-features=false, features = ['alloc'] }