Developer Guid

Installation

Install the Decontext Protocol package via npm:

npm install decontext-protocol

Or clone the full repository:

git clone https://github.com/Decontext/decontext-protocol
cd decontext-protocol
npm install

Project Structure

  • contracts/: Solidity smart contracts implementing DMCP

  • sdk/: TypeScript SDK to interact with context models

  • scripts/: Deployment and utility scripts

  • examples/: Sample code for integration

  • test/: Unit tests using Hardhat

  • docs/: Developer documentation and walkthroughs


Prerequisites

  • Node.js ≥ v16

  • npm ≥ v8

  • Hardhat (for testing/deployment)

  • Metamask-compatible wallet

  • Infura or Alchemy key for Sepolia testnet (or another RPC)


Environment Setup

Create a .env file in the root directory with the following:

SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/YOUR_INFURA_KEY
PRIVATE_KEY=your_wallet_private_key_without_0x
ETHERSCAN_API_KEY=your_etherscan_key

Contract Compilation

Use Hardhat to compile the contracts:

npx hardhat compile

Deploying to Sepolia

You can deploy the DMCP contracts to Sepolia using the included script:

npx hardhat run scripts/deploy.cjs --network sepolia

This will deploy the protocol contracts and output the deployed addresses.


Running Tests

Ensure the protocol behaves correctly using the built-in tests:

npx hardhat test

Using the SDK

You can interact with the protocol using the provided TypeScript SDK in sdk/. Example:

tsCopyEditimport { ContextClient } from "decontext-protocol";

const client = new ContextClient({
  rpcUrl: process.env.SEPOLIA_RPC_URL,
  privateKey: process.env.PRIVATE_KEY,
});

// Fetch context
const userContext = await client.getContext("user.profile", "0xABC...");

// Set new context
await client.setContext("user.reputation", { score: 85 });

The SDK abstracts interaction with DMCP contracts and schema logic, making it easy to build context-aware agents and dApps.


Example Use Case

In the examples/ folder, you'll find templates for:

  • Registering a context schema

  • Updating a user's context

  • Querying an entity's behavior context

  • Integrating with smart contracts or AI agents


Additional Resources


Next Steps

  1. Register a new context schema

  2. Deploy your own context-aware dApp or AI agent

  3. Integrate with other Decontext-compatible modules

Need help? Join the Decontext developer community (Discord/Forum coming soon).

Last updated