How to init AssetId in Storage

First I try to use like this

storage {
    asset_id: AssetId = AssetId::default(),
}

I got “Could not evaluate initializer to a const declaration.” when compile.
Then I try to use like this

storage {
    asset_id: AssetId = AssetId::from_str("0xb9d62dec6e8b87e495772cd81862db31394bfc3b4d1cb6e04c530f21e3ac1f80").unwrap(),
}

I got above 100 errors when compile.
How to solve this problem?

Hey @Clara, can you please try out the solution mentioned here?

Hey @naz3eh When I try to get the type of AssetId

#[storage(read)]
    fn getAssetId() -> AssetId{
        AssetId::default()
    }

I got like this

{
  "bits": "0x787ddef920236e1131aa72bfc80bf1ad23c5b76a959b5a0500f08acf77d39864"
}

it’s not the type of b256, like some wrap b256
If I try to use AssetId like b256

storage {
    asset_id: b256 = 
0xb9d62dec6e8b87e495772cd81862db31394bfc3b4d1cb6e04c530f21e3ac1f80,
}

......
require(storage.asset_id.read() == msg_asset_id(), AssetError::IncorrectAssetSent);
......

I got compile error like this

require(storage.asset_id.read() == msg_asset_id(), AssetError::IncorrectAssetSent);
     |
                                            ^^^^^^^^^^^^^^
 
This parameter was declared as type b256, but argument of type AssetId was provided.

using b256 storage

storage {
    asset_id: b256 = 
0xb9d62dec6e8b87e495772cd81862db31394bfc3b4d1cb6e04c530f21e3ac1f80,
}

and warp is by using

AssetId::from(storage.asset_id.read())

can work

1 Like

Hey @Clara, I am glad it worked for you. let me know if any more help is required :slight_smile:

Thanks @naz3eh
We don’t know when your grant will be reopened. Our full-chain game has been developed for more than a month and will be online in at most one month.

1 Like

you can apply for the grant by filling up this form

Thank you so much @naz3eh

1 Like

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