0

I am new to this IPFS thing and I am really desperate to ask this, I really have no idea how am I going to implement IPFS in my machine, do I need to install something, or where specifially should I run these commands?

IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001");
NamedStreamable.FileWrapper file = new NamedStreamable.FileWrapper(new File("hello.txt"));
MerkleNode addResult = ipfs.add(file).get(0);
Nic3500
  • 8,144
  • 10
  • 29
  • 40

1 Answers1

0

Assuming you want to use java-ipfs-api You're going to need to add the following to your pom.xml file.

  <repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>com.github.ipfs</groupId>
      <artifactId>java-ipfs-api</artifactId>
      <version>v1.2.0</version>
    </dependency>
  </dependencies>

This will download and setup the library for you to write code with. Your code above should work. Here is a complete example if needed

import io.ipfs.api.IPFS;
import io.ipfs.api.MerkleNode;
import io.ipfs.api.NamedStreamable;

import java.io.File;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001");

        NamedStreamable.FileWrapper file = new NamedStreamable.FileWrapper(new File("hello.txt"));

        MerkleNode addResult = ipfs.add(file).get(0);
    }

}
Chris
  • 3,437
  • 6
  • 40
  • 73