Closed schmidsi closed 3 years ago
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)
This might be related: https://github.com/ipfs/go-libipfs/issues/85 And this: https://github.com/ipfs/go-bitswap/issues/513
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"
}
this repo contains that code block.
https://github.com/graphprotocol/ipfs-sync/blob/master/src/commands/sync-files.js
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
The sync script only works for v0.4.23
as --from
but this seems to be out of scope of this issue
i updated npm package version and tried your code. it worked. thanks!
Nice
I think @promaty fixed this. So reassigning & closing.
When trying to pin a file to one of our nodes, the following error is reported: Reported on Discord