Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data.to Data.from #276

Open
hgextracts opened this issue Feb 24, 2025 · 5 comments
Open

Data.to Data.from #276

hgextracts opened this issue Feb 24, 2025 · 5 comments

Comments

@hgextracts
Copy link

Are these no longer available or was this broken in a recent update?

@alessandrokonrad
Copy link
Contributor

They should be still available, nothing changed in that regard. If you have an example where it doesn't work let me know.

@hgextracts
Copy link
Author

im using vite, express, and the @jsr/spacebudz__lucid@^0.20.6. first i was trying to use metadataOf on a cip68 nft but i kept getting a 404 from this. this function used to work also but i haven't been able to get it to work since i upgraded lucid. so then i decided to make the fetches to blockfrost directly for the cip68 metadata then i used Data.from and Data.toJson to convert the metadata, but when i tried i get this

Property 'from' does not exist on type '{ readonly Bytes: (options?: number | { minLength?: number | undefined; maxLength?: number | undefined; enum?: string[] | undefined; } | undefined) => string; readonly Integer: () => bigint; ... 8 more ...; readonly void: () => string; }'.ts(2339)

Property 'toJson' does not exist on type '{ readonly Bytes: (options?: number | { minLength?: number | undefined; maxLength?: number | undefined; enum?: string[] | undefined; } | undefined) => string; readonly Integer: () => bigint; ... 8 more ...; readonly void: () => string; }'.ts(2339)

const datumData = await datumResponse.json();
const parsedDatum = Data.from<Constr>(datumData.cbor);
const metadata = Data.toJson(parsedDatum.fields[0]) as NFTMetadata;

@alessandrokonrad
Copy link
Contributor

alessandrokonrad commented Feb 25, 2025

im using vite, express, and the @jsr/spacebudz__lucid@^0.20.6. first i was trying to use metadataOf on a cip68 nft but i kept getting a 404 from this.

could you let me know which asset/unit you try to get metadata from? The query itself should work.

Property 'from' does not exist on type '...

There's indeed a bug with the npm version of lucid. The TypeScript definition is off and doesn't expose Data.from/to, but the functions are technically there. I'll fix that. You could try in the meantime with (Data as any).to/(Data as any).from.

Property 'toJson' does not exist on type '...

This function does no longer exist. it's now toMetadata and fromMetadata

@hgextracts
Copy link
Author

PolicyId: 7f38ccbe720cecbf652d73f06354690382bb0c943f0a0edc190cac40
Asset Name: 000de1404c434472697665723731

the metadataOf seems to stop working after or around lucid 10.7 i have just been using data.to and from since then

@alessandrokonrad
Copy link
Contributor

PolicyId: 7f38ccbe720cecbf652d73f06354690382bb0c943f0a0edc190cac40
Asset Name: 000de1404c434472697665723731

That's odd. I just tried querying that asset with metadataOf and it works fine. With Deno and NPM version.

You say you are using vite? Have you added the vite wasm plugin to the vite config? If not this might cause the issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants