public-ipfs-gateway
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

public-ipfs-gateway

Get Public IPFS gateway url easily.

Install

  1. Via NPM : npm i public-ipfs-gateway
  2. Via Yarn : yarn add public-ipfs-gateway

Import

  1. CJS : const { getAllGateway, getLiveGateway, getAllLiveGateway } = require('public-ipfs-gateway')
  2. ESM : import { getAllGateway, getLiveGateway, getAllLiveGateway } from 'public-ipfs-gateway'

A. getAllGateway

    import { getAllGateway } from 'public-ipfs-gateway';
    // if use commonjs use this :
    // const { getAllGateway } = require('public-ipfs-gateway');

    // example url
    const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';

    // example function for test
    function test(){
        console.log(getAllGateway(url));
    }
    test();

    // result will be like
    // [
	// 	'https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
	// 	'https://cloudflare-ipfs.com/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
	// 	...
	// ]

B. getLiveGateway

    import { getLiveGateway } from 'public-ipfs-gateway';
    // if use commonjs use this :
    // const { getLiveGateway } = require('public-ipfs-gateway');

    // example url
    const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';

    // example function for test
    async function test(){
        console.log(await getLiveGateway(url));
    }
    test();

    // result will be like
    // https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg

Default timeout is 3000ms, you can set custom timeout by add additional param like await getLiveGateway(url, 5000).

C. getAllLiveGateway

    import { getAllLiveGateway } from 'public-ipfs-gateway';
    // if use commonjs use this :
    // const { getAllLiveGateway } = require('public-ipfs-gateway');

    // example url
    const url = 'ipfs://bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg';

    // example function for test
    async function test(){
        console.log(await getAllLiveGateway(url));
    }
    test();

    // result will be like
    // [
	// 	'https://ipfs.io/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
	// 	'https://cloudflare-ipfs.com/ipfs/bafybeiged4aroumss7u646yl5rzq5xawlvni7velqmwgau6jhxqcpgtf44/metamask-wallet.svg',
	// 	...
	// ]

Default timeout is 3000ms, you can set custom timeout by add additional param like await getLiveGateway(url, 5000).

Package Sidebar

Install

npm i public-ipfs-gateway

Weekly Downloads

0

Version

1.1.6

License

MIT

Unpacked Size

1.14 MB

Total Files

10

Last publish

Collaborators

  • codev911