Skip to main content
In this guide, you will set up and run an example solver that connects to the Message Bus, receives live quote requests, and automatically responds to the ones it can fill.
To become a Market Maker you will need to request an API Key through the Partner Portal and go through KYC/KYB

Getting started

1

Prerequisites

  • Node.js v20.18+ with npm
  • A NEAR mainnet account
2

Clone the Example Solver Repository

The AMM Solver example uses a simple constant-product AMM formula to price quotes
git clone https://github.com/defuse-protocol/near-intents-amm-solver.git
cd near-intents-amm-solver
npm install
3

Configure your environment

Create your environment file from the provided example:
cp env/.env.example env/.env.local
Open env/.env.local and fill your NEAR account credentials, the token pair you want to market-make, and your desired fee margin.
# Your NEAR account credentials
NEAR_ACCOUNT_ID=your-solver.near
NEAR_PRIVATE_KEY=ed25519:your_private_key_here

# The token pair you want to market-make
AMM_TOKEN1_ID=usdt.tether-token.near
AMM_TOKEN2_ID=wrap.near

# Network and mode
NEAR_NETWORK_ID=mainnet
TEE_ENABLED=false

# Your solver will take this percentage from the quoted price as profit (30 bps = 0.3%)
MARGIN_PERCENT=30
4

Get a Message Bus API key

The default Message Bus WebSocket endpoint (wss://solver-relay-v2.chaindefuser.com/ws) requires an API key. To get one:
  1. Sign up at partners.near-intents.org
  2. Request an API key through the partner portal
  3. Undergo KYC/KYB verification as part of the application process
Once issued, add your API key to env/.env.local:
# Message Bus API key
SOLVER_BUS_API_KEY=your_api_key_here
Then open src/services/websocket-connection.service.ts and update the WebSocket connection headers at line 35 to use the environment variable:
headers: {
  Authorization: `Bearer ${process.env.SOLVER_BUS_API_KEY}`,
}
Never commit your private key or API key to version control. The .env.local file is already in .gitignore, but double-check before pushing any changes.
5

Deposit liquidity

Your solver can only fill swaps if it has token balances inside the Verifier contract (intents.near).You need to do two things: register your solver’s public key on the contract, and deposit tokens.
1

Register your public key

npx near-cli-rs contract call-function as-transaction intents.near add_public_key \
  json-args '{"public_key":"ed25519:YOUR_PUBLIC_KEY"}' \
  prepaid-gas '100.0 Tgas' attached-deposit '1 yoctoNEAR' \
  sign-as SOLVER_ACCOUNT_ID network-config mainnet sign-with-keychain send
Replace YOUR_PUBLIC_KEY with the public key that corresponds to the private key in your .env.local file, and SOLVER_ACCOUNT_ID with your actual NEAR account ID.
2

Deposit tokens

The solver needs balances for both tokens in the configured pair. For example, if you are market-making USDT/wNEAR, it needs both usdt.tether-token.near and wrap.near deposited into the contract.
6

Start the solver

Since the environment file is named .env.local, set NODE_ENV=local so the app picks it up:
NODE_ENV=local npm start
On startup, the solver connects to the Message Bus WebSocket, subscribes to quote events, and begins polling the Verifier contract for current token balances every 15 seconds. Log output confirms the connection and initial reserves.
7

Verify it is working

Check the health endpoint to confirm the solver is running:
curl http://localhost:3000
{"ready": true}
In the logs, look for:
  • Connection confirmed - successful WebSocket connection to the Message Bus
  • Quote requests - incoming swap requests being evaluated
  • Quote responses - signed quotes being sent back for pairs your solver supports
The solver only responds to requests for the configured token pair. If a request comes in for a different pair, or if reserves are too low to fill it, the solver skips it.
If quote requests are not appearing, that is normal during low-activity periods. The solver sends responses when matching requests arrive.

Next steps

Now that the solver is running, read the Example Solver guide to understand how the code works — from WebSocket connection through intent signing and settlement — and learn how to customize the pricing logic for your own strategy.