我正在使用js,并希望使用IPFS的发布功能。下面是代码
let result = await ipfs.add("hello");
const ipns_hash = await ipfs.name.publish('/ipfs/'+result.cid)
console.log(ipns_hash)我为上面的发布命令的实现提供了js核心API文档。
这是我在运行上面的命令时遇到的错误,
file:///home/shubh/Desktop/BTech/Project/ipfstrail/node_modules/ipfs-http-client/esm/src/lib/core.js:75
let error = new HTTP.HTTPError(response);
^
**HTTPError: ipns record for f5uxa3ttf4acicabciqiyeamon3gnuvgikdcknbuwyhicyeolhegmomtrvd5fpy53oulfvy could not be stored in the routing**
at Object.errorHandler [as handleError] (file:///home/shubh/Desktop/BTech/Project/ipfstrail/node_modules/ipfs-http-client/esm/src/lib/core.js:75:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.fetch (/home/shubh/Desktop/BTech/Project/ipfstrail/node_modules/ipfs-utils/src/http.js:145:9)
at async Object.publish (file:///home/shubh/Desktop/BTech/Project/ipfstrail/node_modules/ipfs-http-client/esm/src/name/publish.js:6:17)
at async saveText (file:///home/shubh/Desktop/BTech/Project/ipfstrail/app.js:156:23) {
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: true,
ended: true,
endEmitted: true,
reading: false,
constructed: true,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: true,
errored: null,
closed: true,
closeEmitted: true,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: true,
decoder: null,
encoding: null,
[Symbol(kPaused)]: false
},
_events: [Object: null prototype] {
prefinish: [Function: prefinish],
error: [ [Function (anonymous)], [Function (anonymous)] ],
data: [Function (anonymous)],
end: [Function (anonymous)]
},
_eventsCount: 4,
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: true,
needDrain: false,
ending: true,
ended: true,
finished: true,
destroyed: true,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: true,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: true,
closeEmitted: true,
[Symbol(kOnFinished)]: []
},
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
disturbed: true,
error: null
},
[Symbol(Response internals)]: {
url: 'http://localhost:5002/api/v0/name/publish?arg=%2Fipfs%2FQmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX',
status: 500,
statusText: 'Internal Server Error',
headers: Headers {
[Symbol(map)]: [Object: null prototype] {
'content-type': [ 'application/json; charset=utf-8' ],
'cache-control': [ 'no-cache' ],
'content-length': [ '160' ],
date: [ 'Tue, 22 Feb 2022 17:42:43 GMT' ],
connection: [ 'keep-alive' ],
'keep-alive': [ 'timeout=5' ]
}
},
counter: 0
}
}
}有什么解决办法吗?
注意:我正在开发版本^55.0.0的ipfs http-客户端模块。
发布于 2022-09-02 15:11:20
我也是这方面的新手。但是,如果您使用的是"jsipfs守护进程“,那么这也可能是一个问题。我在上面使用了IPFS和凭证(比如,网关和API)。解决了我的问题。
与您不同的是,我分别创建了一个目录,然后将我的文件写入该文件夹。就像下面。
const createdir = async () => {
await ipfs.files.mkdir("/test")
const data = await ipfs.files.stat('/test')
return;
}
const publish = async () => {
const key = Math.floor(Math.random() * 1000);
const buffered = new Buffer.from(JSON.stringify({ content:"some content on the json", key }))
await ipfs.files.write(`/test/${key}.json`, buffered, { create: true });
const folder = await ipfs.files.stat('/test')
const address = folder.cid._baseCache.get("z");
const res = await ipfs.name.publish("/ipfs/" + address)
}而我用的是"ipfs-http-client":"^56.0.3",似乎,最新版本有问题..“js-ipf”:"^0.13.5“
希望能帮上忙。
https://stackoverflow.com/questions/71252212
复制相似问题