TypeScript SDK
The @coti-io/coti-sdk-private-messaging package provides a TypeScript interface for encrypted messaging, reward management, starter grants, and MCP-style tool invocation.
Installation
For the shortest end-to-end setup, use the Private Messaging Quickstart. This page is the SDK reference.
npm install @coti-io/coti-sdk-private-messaging @coti-io/coti-ethersCreate a client
import { Wallet, JsonRpcProvider, CotiNetwork } from "@coti-io/coti-ethers";
import {
getDefaultCotiRpcUrl,
createPrivateMessagingClient
} from "@coti-io/coti-sdk-private-messaging";
const provider = new JsonRpcProvider(getDefaultCotiRpcUrl(CotiNetwork.Testnet));
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
wallet.setAesKey(process.env.AES_KEY!);
const client = createPrivateMessagingClient({
network: CotiNetwork.Testnet,
runner: wallet
});If you do not pass a contractAddress, the SDK uses the built-in defaults:
testnet RPC:
https://testnet.coti.io/rpcmainnet RPC:
https://mainnet.coti.io/rpctestnet messaging contract:
0xa4C514225Db5B8AE6eF1548d4CE912234A7CD954mainnet messaging contract:
0xe461F448cB935a14585F6f1a30F5b4C73ffF8c05
Messaging APIs
The SDK exports the core messaging helpers:
sendMessage
Sends an encrypted message to a recipient address.
to: recipient wallet addressplaintext: plaintext message bodymaxChunkBytes: optional chunk size overridegasLimit: optional manual gas limit override
Important defaults and limits:
default safe chunk size:
24bytesdefault encrypted message gas limit:
8_000_000self-sends are rejected before broadcast
the zero address is rejected before broadcast
messages that exceed the contract chunk limit are rejected before broadcast
Example:
readMessage, listInbox, and listSent
These helpers read individual messages or paginated inbox and sent-message pages. When decrypt is true or omitted, the SDK attempts client-side decryption with the configured runner.
Rewards APIs
The rewards helpers expose the private messaging reward system:
Example:
Starter Grant APIs
The starter grant helpers interact with the external onboarding service:
The SDK defaults to the deployed starter-grant service, so configuration is optional unless you want to override the service URL, timeout, auth token, or install ID path.
MCP-style tools
The package also exports a JSON-safe tool registry and dispatcher:
The MCP tool surface includes:
send_messageread_messagelist_inboxlist_sentget_contract_configget_account_statsget_message_metadataget_current_epochget_epoch_for_timestampget_epoch_usageget_pending_rewardsget_epoch_summaryclaim_rewardsfund_epochget_starter_grant_challengeget_starter_grant_statusclaim_starter_grantrequest_starter_grant
MCP server
The package also ships with a stdio MCP server entrypoint:
If the package is installed in your project, run:
If you are working from the SDK repository checkout, run:
Required environment variables:
PRIVATE_KEYAES_KEYCOTI_NETWORK
Optional overrides:
PRIVATE_MESSAGING_CONTRACT_ADDRESS_OVERRIDECOTI_RPC_URL_OVERRIDECOTI_TESTNET_RPC_URL_OVERRIDECOTI_MAINNET_RPC_URL_OVERRIDESTARTER_GRANT_SERVICE_URLSTARTER_GRANT_SERVICE_TIMEOUT_MSSTARTER_GRANT_SERVICE_AUTH_TOKENSTARTER_GRANT_INSTALL_ID_PATH
Last updated
Was this helpful?