Skip to content

Instantly share code, notes, and snippets.

@apow2
Last active June 27, 2023 06:20
Show Gist options
  • Save apow2/ce6954600be2f9f1d2dc0735ae8a075d to your computer and use it in GitHub Desktop.
Save apow2/ce6954600be2f9f1d2dc0735ae8a075d to your computer and use it in GitHub Desktop.
use axios to get data from IPFS
import axios from "axios";
let myContract;
let init = async () => {
await ethStore.setProvider("https://api.avax-test.network/ext/bc/C/rpc");
await ethStore.setBrowserProvider();
let contract = await new $web3.eth.Contract(abi, contractAddress);
if ($chainId != 43113) {
alert("Warning: You are not connected to Avalanche Fuji test-net!");
}
return contract;
};
setContext("myContract", init());
export function ipfs_url_from_hash(h) {
return "https://ipfs.io/ipfs/" + h;
}
export const getURL = (contract) => async (i) => {
let myContract = await contract;
try {
let val = await myContract.methods.tokenURI(i).call({from:get(selectedAccount)});
let url = await ipfs_url_from_hash(val);
let res = await axios.get(url);
let desc = await res.data.properties.image.description;
let ret = (await "https://ipfs.io/ipfs/") + desc;
return ret;
} catch (err) {
console.warn("Error: " + err);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment