Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosted Service IPFS Node errors #78

Closed
schmidsi opened this issue Jul 8, 2021 · 9 comments
Closed

Hosted Service IPFS Node errors #78

schmidsi opened this issue Jul 8, 2021 · 9 comments
Assignees

Comments

@schmidsi
Copy link
Member

schmidsi commented Jul 8, 2021

When trying to pin a file to one of our nodes, the following error is reported:
Reported on Discord
image

@schmidsi
Copy link
Member Author

schmidsi commented Jul 8, 2021

Code to pin:

const ipfsHttpClient = require('ipfs-http-client')

const createIpfsClient = node => {
    let url
    try {
        url = new URL(node)
    } catch (e) {
        throw new Error(`Invalid IPFS URL: ${node}
  
  The URL must be of the following format: http(s)://host[:port]/[path]`)
    }

    // Set the port to 443 or 80 explicitly, if no port was provided
    let port = url.port
        ? url.port
        : url.protocol === 'https:'
            ? 443
            : url.protocol === 'http'
                ? 80
                : undefined

    // Connect to the IPFS node (if a node address was provided)
    return ipfsHttpClient({
        protocol: url.protocol.replace(/[:]+$/, ''),
        host: url.hostname,
        port: port,
        'api-path': url.pathname.replace(/\/$/, '') + '/api/v0/',
    })
}
export default createIpfsClient
const ipfs = createIpfsClient("https://api.thegraph.com/ipfs/")
await ipfs.pin.add(hash) 

@schmidsi schmidsi self-assigned this Jul 8, 2021
@schmidsi
Copy link
Member Author

schmidsi commented Jul 8, 2021

This might be related: ipfs/boxo#85
And this: ipfs/go-bitswap#513

@promaty
Copy link

promaty commented Jul 8, 2021

I'm not sure where you got that code, but this one works:

const { create } = require('ipfs-http-client')

async function main() {
  const client = create('https://api.thegraph.com/ipfs/api/v0')
  const { cid } = await client.add('hello')
  await client.pin.add(cid) 
  console.log(cid)
}

main()

Package:

  "dependencies": {
    "ipfs-http-client": "^50.1.2"
  }

@canersevince
Copy link

@promaty
Copy link

promaty commented Jul 8, 2021

Just tried running the sync from repo above, works as well:

npm install -g @graphprotocol/ipfs-sync
echo QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN > file-list

docker run --rm -it -d -p 5001:5001 ipfs/go-ipfs:v0.4.23

ipfs-sync sync-files --from https://api.thegraph.com/ipfs --to http://localhost:5001 --file-list file-list
ipfs-sync sync-files --from http://localhost --to https://api.thegraph.com/ipfs --file-list file-list

@promaty
Copy link

promaty commented Jul 8, 2021

The sync script only works for v0.4.23 as --from but this seems to be out of scope of this issue

@canersevince
Copy link

i updated npm package version and tried your code. it worked. thanks!

@promaty
Copy link

promaty commented Jul 8, 2021

Nice

@schmidsi schmidsi assigned promaty and unassigned schmidsi Jul 27, 2021
@schmidsi
Copy link
Member Author

I think @promaty fixed this. So reassigning & closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants