Trait "Hash" is not implemented for type "AssetId" error

Trait “Hash” is not implemented for type “AssetId” error

Hi guys, last week we finally released our swaylend on testnet beta 4, and today I sat down to fix a bug and found out that the contract is not building with an error that never happened before, I want to note that this code was building successfully last week and there were no errors (otherwise how would we release it?).

error
  --> /Users/alexey/projects/fuel/sway-lend/contracts/market/src/main.sw:41:79
   |
39 | 
40 | storage {
41 |     collateral_configurations: StorageMap<AssetId, CollateralConfiguration> = StorageMap {}, 
   |                                                                               ^^^^^^^^^^^^^ Trait "Hash" is not implemented for type "AssetId".
42 |     collateral_configurations_keys: StorageVec<AssetId> = StorageVec {},
43 |     pause_config: PauseConfiguration = PauseConfiguration::default(),
   |

error
   --> /Users/alexey/.forc/git/checkouts/std-9be0d6062747ea7/e75f14b03636bc96751a6760304a1a6d3eb5937d/sway-lib-std/src/hash.sw:322:41
    |
320 | 
321 | #![inline(never)]
322 | pub fn sha256<T>(s: T) -> b256 where T: Hash {
    |                                         ^^^^ Could not find symbol "Hash" in this scope.
323 |     let mut hasher = Hasher::new();
324 |     s.hash(hasher);
    |
____

error
   --> /Users/alexey/.forc/git/checkouts/std-9be0d6062747ea7/e75f14b03636bc96751a6760304a1a6d3eb5937d/sway-lib-std/src/hash.sw:322:41
    |
320 | 
321 | #![inline(never)]
322 | pub fn sha256<T>(s: T) -> b256 where T: Hash {
    |                                         ^^^^ Cannot find trait "Hash" in this scope.
323 |     let mut hasher = Hasher::new();
324 |     s.hash(hasher);
    |
____

Can you please help me figure out how to fix this?

Toolchain

Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains
--------------------
beta-3-aarch64-apple-darwin
beta-4-rc.2-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
hotfix
my-custom-toolchain

active toolchain
-----------------
latest-aarch64-apple-darwin (default)
  forc : 0.46.0
    - forc-client
      - forc-deploy : 0.46.0
      - forc-run : 0.46.0
    - forc-doc : 0.46.0
    - forc-explore : 0.28.1
    - forc-fmt : 0.46.0
    - forc-index : 0.20.10
    - forc-lsp : 0.46.0
    - forc-tx : 0.46.0
    - forc-wallet : 0.3.0
  fuel-core : 0.20.5
  fuel-core-keygen : Error getting version string
  fuel-indexer : 0.20.10

fuels versions
---------------
forc : 0.45
forc-wallet : 0.45

How to reproduce

git clone https://github.com/compolabs/sway-lend.git
cd sway-lend    
git checkout beta-4   
cd contracts/market/
forc build   
1 Like

Hey @fuel please refer to the breaking changes announcement!

In your main.sw simply add the import use std::hash::Hash;

You have an additional error for mismatched types which can be solved by adding AssetId::from(b256)

fn get_reward_token_asset_id() -> AssetId {
    AssetId::from(sha256((contract_id(), ZERO_B256)))
}
1 Like

Oh cool, thanks!!!
Even the lines are normal now, great!

1 Like

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