|
1 |
| -import DaturiansNFT from '../artifacts/Daturians.json'; |
2 |
| -import { ethers } from 'ethers'; |
3 | 1 | import axios from 'axios';
|
4 |
| -import cookie from "cookie"; |
5 |
| -import { |
6 |
| - nftcontractaddress |
7 |
| - } from '../config' |
8 | 2 |
|
9 |
| -export const getMetadataById = async (id) => { |
| 3 | +export const getMetadataById = async (id, contract) => { |
10 | 4 |
|
11 |
| - const ipfs_gateway = "https://daturians.mypinata.cloud/ipfs/" |
12 |
| - const provider = new ethers.providers.JsonRpcProvider("https://polygon-rpc.com/") |
13 |
| - // const provider = new ethers.providers.JsonRpcProvider(node_url) |
14 |
| - const contract = new ethers.Contract(nftcontractaddress, DaturiansNFT.abi, provider) |
15 | 5 | const tokenUri = await contract.tokenURI(id)
|
| 6 | + const ipfs_gateway = "https://daturians.mypinata.cloud/ipfs/" |
16 | 7 |
|
17 |
| - // console.log(tokenUri) |
18 |
| - |
19 | 8 | let newUri = tokenUri.replace("ipfs://", ipfs_gateway)
|
20 | 9 | const meta = await axios.get(newUri)
|
21 |
| - // let price = ethers.utils.formatUnits(i.price.toString(), 'ether') |
22 |
| - // console.log(meta) |
23 | 10 | let imgUri = meta.data.image.replace("ipfs://", ipfs_gateway)
|
24 |
| - // const raw = await axios.get(imgUri, { |
25 |
| - // responseType: "arraybuffer", |
26 |
| - // }) |
27 |
| - // // create a base64 encoded string |
28 |
| - // let base64 = Buffer.from(raw.data, "binary").toString("base64"); |
29 |
| - |
30 |
| - // // create image src |
31 |
| - // let img = 'data:${raw.headers["content-type"]};base64,${base64}'; |
32 |
| - // console.log(img) |
33 | 11 | let item = {
|
34 |
| - // price, |
35 | 12 | tokenId: id,
|
36 |
| - // seller: i.seller, |
37 |
| - // owner: i.owner, |
38 | 13 | image: imgUri,
|
39 | 14 | name: meta.data.name,
|
40 | 15 | description: meta.data.description,
|
41 | 16 | data: meta.data
|
42 | 17 | }
|
43 |
| - // console.log(item) |
44 | 18 | return item
|
45 | 19 | };
|
46 | 20 |
|
47 |
| - export const parseCookies = (req) => { |
48 |
| - return cookie.parse(req ? req.headers.cookie || "" : document.cookie) |
49 |
| - }; |
0 commit comments