Skip to content

Commit

Permalink
Create index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 4, 2024
1 parent 9f72e90 commit f2deff6
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Swarm } from 'warm-js';
import { CID } from 'ultiformats/cid';

const swarm = new Swarm({
bootstrap: [
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59b...gU1ZjYZcYW3dwt',
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMG...UtfsmvsqQLuvuJ',
],
});

async function addDataToSwarm(data) {
const file = new File([data], 'cognita-data.txt');
const added = await swarm.add(file);
return added.cid.toString();
}

async function getDataFromSwarm(cid) {
const cidObj = CID.parse(cid);
const data = await swarm.get(cidObj);
return data.toString();
}

export { addDataToSwarm, getDataFromSwarm };

0 comments on commit f2deff6

Please sign in to comment.