Sending Data
Sending data on the Synternet involves three main steps:
- Register your agent to connect to the network.
- Create services in the marketplace.
- Send the data programmatically in your application using an SDK.
While it's technically possible to do everything through node CLI and raw blockchain transactions, it is error-prone and not recommended. The Portal provides a more straightforward, user-friendly way to register agents and services. Once that setup is complete, you can interact with the data programmatically through SDKs or basic CLI tools.
We assume you already have the Keplr wallet installed and connected with some mainnet SYNT or testnet AMBER token. If not, please return to the previous section to set up your wallet.
Prerequisites
Before continuing, make sure the following are in place:
- You have the Keplr wallet installed in your browser.
- Wallet is connected to either mainnet (with SYNT tokens) or testnet (with AMBER tokens).
Refer to the wallet setup guide if you haven't set this up yet.
Registering Agent
You must register an agent in the Synternet Portal to access the Synternet network. To create an agent, navigate to the My Agents tab in the Synternet Portal (testnet, mainnet) and click on Register an agent.
Each agent has:
- An image is displayed in marketplace.
- A label is displayed in marketplace and is used during filtering.
- A subject name - a string uniquely identifying agent service name.
- An optional description is displayed in marketplace.
- An access token — a secret key derived from your wallet signature. Available once you create a agent by clicking on the specific agent ellipsis menu and the Reveal Access Token button.
When you register an agent, a fee of 50 SYNT (or 50 AMBER on testnet) will be reserved from your account. These credits remain locked for the duration of the agent service and are fully refunded to your balance when the agent is removed.
This access token is what your agent will use to authenticate itself when sending data. At this point, you can already use this access token to connect to the Synternet network. However, you will not be able to send any data, since the data stream itself inside of agent service is not yet registered.
// npm i [email protected]:Synternet/pubsub-js.git
import { createAppJwt, NatsService } from "pubsub-js";
const accessToken = "secret-project-revealed-access-token";
async function main() {
const service = new NatsService({
url: "europe-west3-gcp-dl-testnet-brokernode-frankfurt01.synternet.com",
natsCredsFile: createAppJwt(accessToken),
});
await service.waitForConnection().catch((err) => {
console.error("Failed to connect.", err);
process.exit(1);
});
console.info("Connected!");
}
main();
The Synternet network is a proof-of-authority messaging layer that connects to the Synternet blockchain to verify user access. It is responsible for delivering messages between agents.
- Mainnet
- Testnet
broker-eu-01.synternet.com
broker-eu-02.synternet.com
broker-eu-03.synternet.com
europe-west3-gcp-dl-testnet-brokernode-frankfurt01.synternet.com
europe-west3-gcp-dl-testnet-brokernode-frankfurt02.synternet.com
europe-west3-gcp-dl-testnet-brokernode-frankfurt03.synternet.com
Use one of the Synternet network node URLs above to connect your agent to the Synternet network, depending on whether you're working on mainnet or testnet.
Creating Services
At this point, you should already be able to connect to the Synternet network. With agent created in previous step, you can now create streams services:
- Go to your project in the Portal (testnet, mainnet).
- Click My Agents.
- Select agent you want to add a stream to.
- Click Add New Service.
- Confirm the transaction to register a service.
Each service has:
- An optional image is displayed in marketplace. Agent image is used if not supplied.
- A label is displayed in marketplace and is used during filtering.
- A subject name - a string uniquely identifying stream service.
- An optional description is displayed in marketplace.
- Service type: Stream (one way data streaming, agent is producer), RPC (for request-reply style communication).
- Fee rate - a fee agent receives for delivering messages (can be free, but network fee always applies)
Sending the Data
All services linked to an agent are writeable with the same token, making it easy to manage access per agent. How you send data differs depending on whether the data you subscribe to is a stream-like or RPC-like service. Stream-like service continuously pushes to your client without requests, and RPC-like data responds to your clients requests.
- Stream
- RPC
// npm i [email protected]:Synternet/pubsub-js.git
import { createAppJwt, NatsService } from "pubsub-js";
const accessToken =
"secret-project-revealed-access-token";
const subject = "synternet.osmosis.rpc";
const message = '{"endpoint":"header","params":{"height":"20121934"}}';
async function main() {
const service = new NatsService({
url: "europe-west3-gcp-dal-devnet-brokernode-cluster01.synternet.com",
natsCredsFile: createAppJwt(accessToken),
});
await service.waitForConnection();
console.log(
`Publishing message: ${JSON.stringify(message)} to subject: ${subject}`,
);
service.publishJSON(subject, message);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
// npm i [email protected]:Synternet/pubsub-js.git
import { createAppJwt, NatsService } from "pubsub-js";
const accessToken =
"secret-project-revealed-access-token";
const rpcSubject = "synternet.osmosis.rpc";
const rpcRequest = '{"endpoint":"header","params":{"height":"20121934"}}';
async function main() {
const service = new NatsService({
url: "europe-west3-gcp-dal-devnet-brokernode-cluster01.synternet.com",
natsCredsFile: createAppJwt(accessToken),
});
await service.waitForConnection();
const msg = await service.request(rpcSubject, rpcRequest);
console.info(new TextDecoder().decode(msg.data));
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
See Receiving Data to learn how to consume stream.
See the Synternet SDKs page for support in additional programming languages. Most SDKs also include usage examples and extended documentation in their respective repositories.
Next up: getting help.