Skip to content

Instantly share code, notes, and snippets.

@Jesserc
Forked from apow2/axios.js
Created October 31, 2022 22:31
Show Gist options
  • Select an option

  • Save Jesserc/eab797f7868b1e0e734076a21768ed34 to your computer and use it in GitHub Desktop.

Select an option

Save Jesserc/eab797f7868b1e0e734076a21768ed34 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