-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: how do you create an in-memory offline ipfs node for testing? #2751
Comments
If await ipfs.block.put(value, { cid: key }) https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/BLOCK.md#blockput |
Thanks, I’m sure that helps but it’s still not working. https://github.com/mikeal/ipfs-for-car/blob/master/index.js I get
|
Can you share the car file and I can take a look? |
This is a bug in You can (hopefully) work around this for now by doing: await ipfs.block.put(value, { cid: new CID(key) }) |
thanks! :) it works with this workaround now. |
It took some trial and error (and poking around in the js-ipfs-repo code; the docs aren't up to date with the latest API), but this did the job for me:
|
Just to update this a little, using IPFS v0.60.2 with TypeScript, to get the above working I needed to change it to: import * as IPFS from 'ipfs';
import { MemoryDatastore } from 'datastore-core';
import { MemoryBlockstore } from 'blockstore-core';
import { createRepo } from 'ipfs-repo';
import { MemoryLock } from 'ipfs-repo/locks/memory'
import * as rawCodec from 'multiformats/codecs/raw';
const repo = createRepo(
'',
async () => rawCodec,
{
blocks: new MemoryBlockstore(),
datastore: new MemoryDatastore(),
keys: new MemoryDatastore(),
pins: new MemoryDatastore(),
root: new MemoryDatastore()
},
{ autoMigrate: false, repoLock: MemoryLock, repoOwner: true }
);
const ipfs = await IPFS.create({ repo }); |
I’ve been trying to create a purely in-memory offline ipfs node and it doesn’t appear to be working. The node appears to function but blocks I’ve just added aren’t actually available. https://github.com/mikeal/ipfs-for-car/blob/master/index.js#L1-L31
The text was updated successfully, but these errors were encountered: