Invalid enum data size in metadata SRC7

In this code:

storage {
     metadatas: StorageMetadata = StorageMetadata {},
    ctr: u256 = 0,
    total_assets: u64 = 0,

}

impl SRC7 for Contract {
    #[storage(read)]
    fn metadata(asset: AssetId, key: String) -> Option<Metadata> {
        // Return the stored metadata
        storage.metadatas.get(asset, key)
    }
}

When I try to query the data like this using TS SDK:

    let assetId: AssetIdInput = {
      bits: "0xa875fa4f00180c89155ee08e726a3c9ca2924cf9389ef6bbb82b8ebcd4a64649",
    };
    const data = await contract.functions.metadata(assetId, "key1").get();

I am getting this error:

Error:  _FuelError: Invalid enum data size.
    at OptionCoder.decode

This is how I set the metadata in my mint function:

abi MintWithMetadata {
    #[storage(read, write)]
    fn mint(recipient: Identity, keys: Vec<String>, metadatas: Vec<Metadata>);
}

impl MintWithMetadata for Contract {
    #[storage(read, write)]
    fn mint(recipient: Identity, keys: Vec<String>, metadatas: Vec<Metadata>) {
        require(keys.len() == metadatas.len(), "invalid-key-metadata-length");
        only_owner();
        let sub_id = storage.ctr.read().as_b256();
        let mut i:u64 = 0;
        while i < keys.len() {
            let asset_id = AssetId::new(ContractId::this(), sub_id);
            _set_metadata(storage.metadatas, asset_id, keys.get(i).unwrap(), metadatas.get(i).unwrap());
            i += 1;
        }
        storage.ctr.write(storage.ctr.read() + 1);
        mint_to(recipient, sub_id, 1);
        storage.total_assets.write(storage.total_assets.read() + 1);
    }
}

What am I doing wrong here?

fuelup show:

testnet-x86_64-unknown-linux-gnu (override)

Hey, would you mind sharing the version of the fuels TS SDK you are using? And the complete contents of fuelup show, so that it includes all the versions.

sure,

  • fuels TS SDK version: 0.88.0
  • complete fuelup show
Default host: x86_64-unknown-linux-gnu
fuelup home: /home/tit4n/.fuelup

installed toolchains
--------------------
beta-5-x86_64-unknown-linux-gnu
latest-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)
nightly-2024-04-12-x86_64-unknown-linux-gnu
testnet-x86_64-unknown-linux-gnu (override)

active toolchain
----------------
testnet-x86_64-unknown-linux-gnu (override), path: /home/tit4n/lync/fuel/Fuel-Contracts/deployer-contracts/fuel-toolchain.toml
  forc : 0.59.0
    - forc-client
      - forc-deploy : 0.59.0
      - forc-run : 0.59.0
    - forc-crypto : 0.59.0
    - forc-debug : 0.59.0
    - forc-doc : 0.59.0
    - forc-explore : 0.28.1
    - forc-fmt : 0.59.0
    - forc-lsp : 0.59.0
    - forc-tx : 0.59.0
    - forc-wallet : 0.7.1
  fuel-core : 0.26.0
  fuel-core-keygen : 0.26.0

fuels versions
--------------
forc : 0.62.0
forc-wallet : 0.62.0

1 Like

Please could you upgrade your fuels version to the latest, 0.90.0. We found an issue with enum validation that was resolved here and included in 0.88.1. However I’d recommend upgrading to the latest version if you are working on testnet.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.