我试图使用轨道数据库,所以我遵循导游.但是在https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#create-a-database,我得到了一个错误:
const ipfs = new IPFS()
^
TypeError: IPFS is not a constructor这是我的完整代码:
const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
// Create IPFS instance
const ipfs = new IPFS()
ipfs.on('ready', async () => {
const orbitdb = await OrbitDB.createInstance(ipfs)
const db = await orbitdb.docs('opews-db-test1')
const address = db.address
})我检查了使用require()的console.log()中没有错误,但似乎没有。所以我不知道怎么解决..。
发布于 2020-05-13 09:06:24
IPFS已经改变了构建IPFS节点的方式,您可以试试以下代码:
const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
async function main() {
const ipfs = await IPFS.create();
const orbitdb = await OrbitDB.createInstance(ipfs);
const db = await orbitdb.docs('opews-db-test1');
const address = db.address;
}
main();发布于 2022-03-21 06:53:45
一个完整的例子:
<!doctype html>
<html>
<head>
<title>IPFS in the Browser</title>
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/orbit-db/dist/orbitdb.js"></script>
<script type="text/javascript">
(async function main()
{
node = await Ipfs.create({
repo: "ipfs/shared",
config: {"Bootstrap": ["/ipv4/127.0.0.1/tcp/4002/ws/ipfs/<your go-ipfs peer id>"]},
EXPERIMENTAL: {pubsub: true }});
console.log('Online status: ', node.isOnline() ? 'online' : 'offline')
document.getElementById("status").innerHTML= 'Node status: ' + (node.isOnline() ? 'online' : 'offline')
orbit = await OrbitDB.createInstance(node);
docs = await orbit.docs('my-docs', { indexBy: 'name' })
hash = await docs.put({name: 'shamb0t', followers: 500 })
console.log(hash)
console.log(docs.get('shamb0t')[0].followers)
feed = await orbit.feed('my-feed');
hash = await feed.add('hello');
console.log(hash);
console.log(feed.iterator({ limit: -1 }).collect()[0].payload.value)
//feed.del(hash)
})()
</script>
</head>
<body>
<h1 id="status">Node status: offline</h1>
</body>
</html>https://stackoverflow.com/questions/61770044
复制相似问题