Skip to content

Instantly share code, notes, and snippets.

@martenc
Created May 4, 2024 14:32
Show Gist options
  • Save martenc/56f52c6e1dca1f898f94f4465fa6e218 to your computer and use it in GitHub Desktop.
Save martenc/56f52c6e1dca1f898f94f4465fa6e218 to your computer and use it in GitHub Desktop.
Parse IPFS json to get img url
/*
input to parse:
{"image":"ipfs://QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/de22e8bd5787802d7417009f647bb33b","name":"2 kilobytes low cost Token Eric #137"}
output:
https://cf-ipfs.com/ipfs/QmTE4k9xCaZHKpEmk1vf56xPQdWghtKpT5GZCRbf2eYoSw/72315d4fbdc4e2d96ea6777b67b5f8a8
*/
function convertIpfsUrl(ipfsUrl: string): string {
const cid = ipfsUrl.replace("ipfs://", "");
const ipfsDomain = "cf-ipfs.com/ipfs";
const transformedUrl = `https://${ipfsDomain}/${cid}`;
return transformedUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment