I am trying to read metadata in TS from the NFT contract.
error:-
/// use std::string::String;
///
/// fn foo(contract_id: ContractId, asset: AssetId) {
/// let contract_abi = abi(SRC7, contract_id);
/// let key = String::from_ascii_str("image");
/// let data = contract_abi.metadata(asset, key);
/// assert(data.is_some());
/// }
/// ```
#[storage(read)]
fn metadata(asset: AssetId, key: String) -> Option<Metadata> {
storage.metadata.get(asset, key)
}
}
impl SetAssetAttributes for Contract {
/// Sets the name of an asset.
///
/// # Arguments
///
/// * `asset`: [AssetId] - The asset of which to set the name.
const contract = await getContract();
const metadata: MetadataInput = { String: "https://bafkreidhmmldn6o5nxyfqf65x5jz7f66qcj4xy2axv2onefkzdbv4i7yta.ipfs.w3s.link" };
const id = { value: "0xa74dcc2789f5643a27750d6f0f2dfb2b6d5d39bb74c0911e4d8114f8d66fa2d1" };
const res = await contract.functions.set_metadata(id, "0", metadata).txParams({ gasPrice: 100, gasLimit: 10000 }).call();
console.log(res);
};```
reading metadata
```const getmetadata = async () => {
const contract = await getContract();
const wallet = await getWallet();
const id = { value: "0xa74dcc2789f5643a27750d6f0f2dfb2b6d5d39bb74c0911e4d8114f8d66fa2d1" };
const res = await contract.functions.metadata(id, "0").txParams({ gasLimit: 10000 }).simulate();
console.log(res);
}
Hi @chappie1998 , could you please share which version of the TypeScript SDK you’re currently using? Also, I’m interested in knowing the version of Sway you’re working with. Thank you!
I am on beta5 toolchain. all the SDKs and sway is latest version.
forc 0.49.1
“fuels”: “^0.73.0”,
@nedsalk , @Torres-ssf any idea about this?
@chappie1998 hey I’m looking into this. Could you share your Forc.toml
file?
1 Like
If you have a repo that you could share that would be awesome too. Would allow me to reproduce this error easily and then work on a fix
1 Like
it’s an NFT contract from sway application
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "NFT-contract"
[dependencies]
asset = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.18.0" }
src20 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
src3 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
src7 = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.3.3" }
I see. Are you able to set the metadata? Is the problem only with reading it?
I am able to set the metadata. This is my TS code for that
console.log("metadata start");
const contract = await getContract();
const wallet = await getWallet();
// console.log(await wallet.getBalances());
const metadata: MetadataInput = { String: "https://bafkreidhmmldn6o5nxyfqf65x5jz7f66qcj4xy2axv2onefkzdbv4i7yta.ipfs.w3s.link" };
const id = { value: "0x36e2674c59665fc43a11546ef95054da5fab342b94ffb1a430246b59cef17e12" };
const res = await contract.functions.set_metadata(id, "0", metadata).txParams({ gasPrice: 100, gasLimit: 10000 }).call();
console.log(res);
};```
1 Like
chappie1998 Is this problem only happening when you try to read the metadata, right?
Does the contract call to set the metadata works ok?
@Torres-ssf yes setting metadata works fine.
@chappie1998 I was able to reproduce this. I’ve filed an issue: Unable to read SRC7 metadata via the TS SDK · Issue #1880 · FuelLabs/fuels-ts · GitHub and am now working on a fix. Will get back to you once we have a fix. Thanks for your patience
1 Like