TypeScript

💡

N1 is currently in closed early access and only available to select developers. These docs are meant to provide insight into what developing on N1 feels like. If you are interested in developing an app on N1, sign up to the Early Access Program ↗ (opens in a new tab).

We provide a deterministic environment for running TypeScript applications, which support most packages with some limitations. We provide a thin package to send and receive messages to and from the rest of the network.

import { send, recv, U256 } from "n1-sdk";
 
// Encode the message however you like. Here, we use JSON.
let message = Buffer.from(JSON.stringify({ action: "hi!" }));
let dest = U256.from(/* destination address */);
 
// Send the message to the destination. We handle the routing.
send(message, dest);
 
// Receive a message. This pops a message from the underlying
// queue. Will return null if the inbox is empty
let result = recv();
 
if (result !== null) {
  let { message, sender } = result;
  // Do something with the message.
}