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

return metadataUrl #80

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ function Nft() {
<img src={nft.image} alt="" />
<p>{nft.description}</p>
<p>Owner: {nft.owner}</p>
</section>
<p>Metadata URL: {nft.metadataUrl}</p>
</section>
)
}
```
Expand Down Expand Up @@ -125,6 +126,10 @@ result.nft.image

// current owner of the NFT (or empty string)
result.nft.owner

// url of the json containing the NFT's metadata
result.nft.metadataUrl

```

As TypeScript type:
Expand All @@ -140,6 +145,7 @@ type NftResult = {
image: string
name: string
owner: string
metadataUrl?: string
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/fetchers/ethereum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ethereumFetcher(

const metadata = await fetchMetadata(metadataUrl)

return { ...metadata, owner }
return { ...metadata, owner, metadataUrl }
},
}
}
2 changes: 1 addition & 1 deletion src/fetchers/ethers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ethersFetcher(

const metadata = await fetchMetadata(metadataUrl)

return { ...metadata, owner }
return { ...metadata, owner, metadataUrl }
},
}
}
4 changes: 3 additions & 1 deletion src/fetchers/shared/cryptokitties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { CRYPTOKITTIES } from "../../known-contracts"
import { addressesEqual } from "../../utils"

export async function cryptoKittiesMetadata(id: string): Promise<NftMetadata> {
const res = await fetch(`https://api.cryptokitties.co/v3/kitties/${id}`)
const metadataUrl = `https://api.cryptokitties.co/v3/kitties/${id}`;
const res = await fetch(metadataUrl)
const data = (await res.json()) as {
name: string
bio: string
Expand All @@ -15,6 +16,7 @@ export async function cryptoKittiesMetadata(id: string): Promise<NftMetadata> {
image: data?.image_url ?? "",
name: data?.name ?? "Unknown",
owner: "",
metadataUrl,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type NftMetadata = {
image: string
name: string
owner: Address
metadataUrl?: string
}

export type NftJsonMetadata = {
Expand Down