I want to create an OrbitDB database with a locally running IPFS daemon.
My code is based on a code sample published in a past discussion, with a few changes.
Here is my code (test.js):
import * as IpfsClient from 'ipfs-http-client'
import OrbitDB from 'orbit-db'
const ipfs = IpfsClient.create('/ip4/127.0.0.1/tcp/5001')
const orbitdb = await OrbitDB.createInstance(ipfs)
const db = await orbitdb.eventlog('mydatabase')
I started the IPFS daemon by ipfs daemon
.
When I run my code with node test.js
, it fails on the last line. I am getting the following error:
/home/me/node_modules/ipfs-http-client/src/lib/core.js:100
let error = new HTTP.HTTPError(response)
^
HTTPError: URL arg must be multibase encoded: selected encoding not supported
at Object.errorHandler [as handleError] (/home/me/node_modules/ipfs-http-client/src/lib/core.js:100:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.fetch (/home/me/node_modules/ipfs-http-client/node_modules/ipfs-utils/src/http.js:145:9) {
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://127.0.0.1:5001/api/v0/pubsub/sub?arg=%2Forbitdb%2F.............%2Fmydatabase',
status: 500,
statusText: 'Internal Server Error',
headers: Headers {
[Symbol(map)]: [Object: null prototype] {
'access-control-allow-headers': [ 'X-Stream-Output, X-Chunked-Output, X-Content-Length' ],
'access-control-expose-headers': [ 'X-Stream-Output, X-Chunked-Output, X-Content-Length' ],
'content-type': [ 'application/json' ],
server: [ 'kubo/0.16.0' ],
trailer: [ 'X-Stream-Error' ],
vary: [ 'Origin' ],
date: [ 'Thu, 01 May 2023 01:00:00 GMT' ],
'transfer-encoding': [ 'chunked' ]
}
},
counter: 0
}
}
}
I am not sure, but it seems to me that the IPFS daemon does not allow me to create a database (or generally a file). What is missing here? How can I solve this problem?