diff --git a/README.md b/README.md index 9582274..8162d0d 100644 --- a/README.md +++ b/README.md @@ -429,10 +429,22 @@ npm install ##### Upload `Image` to `IPFS` +Get IPFS infura credentials [here](https://infura.io/). Remeber to create a DEDICATED GATEWAY SUBDOMAIN to get uploaded files. + ```javascripts -import { create as ipfsHttpClient } from 'ipfs-http-client' +import { create } from 'ipfs-http-client'; + +const auth = + 'Basic ' + Buffer.from(INFURA_IPFS_ID + ':' + INFURA_IPFS_SECRET).toString('base64'); -const client = ipfsHttpClient('https://ipfs.infura.io:5001/api/v0'); +const client = create({ + host: 'ipfs.infura.io', + port: 5001, + protocol: 'https', + headers: { + authorization: auth, + }, + }); async function onChange(e) { const file = e.target.files[0]; @@ -443,7 +455,7 @@ async function onChange(e) { progress: (prog) => console.log(`received: ${prog}`) } ); - const url = `https://ipfs.infura.io/ipfs/${added.path}`; + const url = `YOUR_DEDICATED_DOMAIN/ipfs/${added.path}`; setFileUrl(url) } catch (error) { console.log('Error uploading file: ', error) diff --git a/src/components/NFTMarket/index.js b/src/components/NFTMarket/index.js index bc6b727..dc6aea5 100755 --- a/src/components/NFTMarket/index.js +++ b/src/components/NFTMarket/index.js @@ -1,6 +1,6 @@ import React from 'react' import { ethers } from 'ethers' -import { create as ipfsHttpClient } from 'ipfs-http-client' +import { create } from 'ipfs-http-client'; import { Button, Form, Header, Image, Input, Modal } from 'semantic-ui-react' import './nft.css' @@ -9,7 +9,17 @@ import NFTMarket from '../../abis/NFTMarket' import { useWeb3React } from '@web3-react/core' import { nftaddress, nftmarketaddress } from '../../config' -const client = ipfsHttpClient('https://ipfs.infura.io:5001/api/v0'); +const auth = + 'Basic ' + Buffer.from(INFURA_IPFS_ID + ':' + INFURA_IPFS_SECRET).toString('base64'); + +const client = create({ + host: 'ipfs.infura.io', + port: 5001, + protocol: 'https', + headers: { + authorization: auth, + }, +}); const FormNoFile = { @@ -43,7 +53,7 @@ export default function NFTDAppIndex() { progress: (prog) => console.log(`received: ${prog}`) } ); - const url = `https://ipfs.infura.io/ipfs/${added.path}`; + const url = `{YOUR_DEDICATED_DOMAIN}/ipfs/${added.path}`; setFileUrl(url) } catch (error) { console.log('Error uploading file: ', error)