9

I have an idea for an IXI module that I'd like to try out, but I don't understand how I'm supposed to implement it.

I'd like to start with an example; what would an "Hello world!" version of an IXI module look like?

  • I don't know of any documentation for IXI modules (or whether the API is even considered stable). Generally, they are just JavaScript modules which use the Rhino JavaScript engine to directly call the Java methods of iri. There is the parsing of package.json etc implemented: github.com/iotaledger/iri/blob/… and here is a test case including a minimal ixi module: github.com/iotaledger/iri/blob/… – mihi Dec 10 '17 at 21:16
  • Question edited to be more specific. – user5568265 Dec 11 '17 at 7:25
6

ixi/hello_world/package.json

{"main": "index.js"}

ixi/hello_world/index.js

function hello_world_impl(req) {
    return com.iota.iri.service.dto.IXIResponse.create({greeting: "Hello, world!"});
}

API.put("helloWorld", new com.iota.iri.service.CallableRequest({call: hello_world_impl}));

How to call:

curl http://localhost:14700 -X POST -H 'X-IOTA-API-Version: 1.4.1' -H 'Content-Type: application/json' -d '{"command": "hello_world.helloWorld"}'

Reply:

{"ixi":{"greeting":"Hello, world!"},"duration":2}

There is also Snapshot.ixi for a more realistic example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.