Skip to content

Commit 0e91efe

Browse files
author
vcart
committed
chore: fixed RPC issues, removed .env
1 parent ced7dbf commit 0e91efe

10 files changed

Lines changed: 85 additions & 59 deletions

File tree

.env.example

Lines changed: 0 additions & 6 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ logs
1515
_.log
1616
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
1717

18-
# dotenv environment variable files
19-
.env
20-
.env.development.local
21-
.env.test.local
22-
.env.production.local
23-
.env.local
24-
2518
# caches
2619
.eslintcache
2720
.cache

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A comprehensive Model Context Protocol (MCP) server that provides blockchain ope
1414
- [Supported Networks](#supported-networks)
1515
- [Prerequisites](#prerequisites)
1616
- [Installation](#installation)
17-
- [Configuration](#configuration)
17+
- [Server Configuration](#server-configuration)
1818
- [Usage](#usage)
1919
- [API Reference](#api-reference)
2020
- [Tools](#tools)
@@ -154,20 +154,18 @@ bun install
154154
npm install
155155
```
156156

157-
## ⚙️ Configuration
157+
## ⚙️ Server Configuration
158158

159-
The server uses public RPC endpoints by default for all supported networks. For production use, you can configure server settings by:
159+
The server uses the following default configuration:
160160

161-
1. Create a `.env` file in the project root
162-
2. Add custom configurations for any settings you want to override:
161+
- **Default Chain ID**: 1 (Ethereum Mainnet)
162+
- **Server Port**: 3001
163+
- **Server Host**: 0.0.0.0 (accessible from any network interface)
163164

164-
```env
165-
# Example .env configuration
166-
DEFAULT_CHAIN_ID=1 # The default chain ID to use if no chain ID is provided (default: Ethereum Mainnet)
167-
SERVER_PORT=3001 # The port to run the server on (default: 3001)
168-
SERVER_HOST=localhost # The host to run the server on (default: localhost)
165+
These values are hardcoded in the application. If you need to modify them, you can edit the following files:
169166

170-
```
167+
- For chain configuration: `src/core/chains.ts`
168+
- For server configuration: `src/server/http-server.ts`
171169

172170
## 🚀 Usage
173171

@@ -327,6 +325,7 @@ To modify or extend the server:
327325
2. Register new tools in `src/core/tools.ts`
328326
3. Register new resources in `src/core/resources.ts`
329327
4. Add new network support in `src/core/chains.ts`
328+
5. To change server configuration, edit the hardcoded values in `src/server/http-server.ts`
330329

331330
## 📄 License
332331

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"dependencies": {
2525
"@modelcontextprotocol/sdk": "^1.6.1",
2626
"cors": "^2.8.5",
27-
"dotenv": "^16.4.7",
2827
"express": "^4.21.2",
2928
"viem": "^2.23.8",
3029
"zod": "^3.24.2"

src/core/chains.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ import {
5555
holesky
5656
} from 'viem/chains';
5757

58-
// Load default config from environment variables
59-
export const DEFAULT_RPC_URL = process.env.DEFAULT_RPC_URL || 'https://eth.llamarpc.com';
60-
export const DEFAULT_CHAIN_ID = parseInt(process.env.DEFAULT_CHAIN_ID || '1');
58+
// Default configuration values
59+
export const DEFAULT_RPC_URL = 'https://eth.llamarpc.com';
60+
export const DEFAULT_CHAIN_ID = 1;
6161

6262
// Map chain IDs to chains
6363
export const chainMap: Record<number, Chain> = {
@@ -239,7 +239,7 @@ export const rpcUrlMap: Record<number, string> = {
239239
7700: 'https://canto.gravitychain.io',
240240

241241
// Testnets
242-
11155111: 'https://rpc.sepolia.org',
242+
11155111: 'https://sepolia.drpc.org',
243243
11155420: 'https://sepolia.optimism.io',
244244
421614: 'https://sepolia-rpc.arbitrum.io/rpc',
245245
84532: 'https://sepolia.base.org',

src/core/operations/transfer.ts

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,24 @@ const erc1155TransferAbi = [
115115

116116
/**
117117
* Transfer ETH to an address
118+
* @param privateKey The private key of the sender
119+
* @param to The recipient address
120+
* @param amount The amount to transfer as a human-readable string in ETH (e.g. "0.1" for 0.1 ETH)
121+
* @param network The network to use
122+
* @returns Transaction hash
118123
*/
119124
export async function transferETH(
120-
privateKey: Hex,
125+
privateKey: string | Hex,
121126
to: Address,
122127
amount: string, // in ether
123128
network = 'ethereum'
124129
): Promise<Hash> {
125-
const client = getWalletClient(privateKey, network);
130+
// Ensure the private key has 0x prefix
131+
const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
132+
? `0x${privateKey}` as Hex
133+
: privateKey as Hex;
134+
135+
const client = getWalletClient(formattedKey, network);
126136

127137
// Convert amount from ether to wei
128138
const value = parseEther(amount);
@@ -138,12 +148,18 @@ export async function transferETH(
138148

139149
/**
140150
* Transfer ERC20 tokens from one address to another
151+
* @param tokenAddress The address of the ERC20 token contract
152+
* @param toAddress The recipient address
153+
* @param amount The amount to transfer as a human-readable string (e.g. "1.5" for 1.5 tokens)
154+
* @param privateKey The private key of the sender
155+
* @param network The network to use
156+
* @returns Transaction details
141157
*/
142158
export async function transferERC20(
143159
tokenAddress: Address,
144160
toAddress: Address,
145161
amount: string,
146-
privateKey: `0x${string}`,
162+
privateKey: string | `0x${string}`,
147163
network: string = 'ethereum'
148164
): Promise<{
149165
txHash: Hash;
@@ -156,8 +172,13 @@ export async function transferERC20(
156172
decimals: number;
157173
};
158174
}> {
175+
// Ensure the private key has 0x prefix
176+
const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
177+
? `0x${privateKey}` as Hex
178+
: privateKey as Hex;
179+
159180
const publicClient = getPublicClient(network);
160-
const walletClient = getWalletClient(privateKey, network);
181+
const walletClient = getWalletClient(formattedKey, network);
161182
const account = walletClient.account!;
162183
const chain = getChain(network);
163184

@@ -201,12 +222,18 @@ export async function transferERC20(
201222

202223
/**
203224
* Approve another address to spend a specific amount of tokens
225+
* @param tokenAddress The address of the ERC20 token contract
226+
* @param spenderAddress The address to approve for spending
227+
* @param amount The amount to approve as a human-readable string (e.g. "1.5" for 1.5 tokens)
228+
* @param privateKey The private key of the token owner
229+
* @param network The network to use
230+
* @returns Transaction details
204231
*/
205232
export async function approveERC20(
206233
tokenAddress: Address,
207234
spenderAddress: Address,
208235
amount: string,
209-
privateKey: `0x${string}`,
236+
privateKey: string | `0x${string}`,
210237
network: string = 'ethereum'
211238
): Promise<{
212239
txHash: Hash;
@@ -219,8 +246,13 @@ export async function approveERC20(
219246
decimals: number;
220247
};
221248
}> {
249+
// Ensure the private key has 0x prefix
250+
const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
251+
? `0x${privateKey}` as Hex
252+
: privateKey as Hex;
253+
222254
const publicClient = getPublicClient(network);
223-
const walletClient = getWalletClient(privateKey, network);
255+
const walletClient = getWalletClient(formattedKey, network);
224256
const account = walletClient.account!;
225257
const chain = getChain(network);
226258

@@ -269,7 +301,7 @@ export async function transferERC721(
269301
tokenAddress: Address,
270302
toAddress: Address,
271303
tokenId: bigint,
272-
privateKey: `0x${string}`,
304+
privateKey: string | `0x${string}`,
273305
network: string = 'ethereum'
274306
): Promise<{
275307
txHash: Hash;
@@ -279,8 +311,13 @@ export async function transferERC721(
279311
symbol: string;
280312
};
281313
}> {
314+
// Ensure the private key has 0x prefix
315+
const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
316+
? `0x${privateKey}` as Hex
317+
: privateKey as Hex;
318+
282319
const publicClient = getPublicClient(network);
283-
const walletClient = getWalletClient(privateKey, network);
320+
const walletClient = getWalletClient(formattedKey, network);
284321
const account = walletClient.account!;
285322
const fromAddress = account.address;
286323
const chain = getChain(network);
@@ -325,25 +362,40 @@ export async function transferERC721(
325362

326363
/**
327364
* Transfer an ERC1155 token
365+
* @param tokenAddress The address of the ERC1155 token contract
366+
* @param toAddress The recipient address
367+
* @param tokenId The ID of the token to transfer
368+
* @param amount The amount to transfer as a string (ERC1155 tokens don't typically have decimals, but we use string for consistency)
369+
* @param privateKey The private key of the sender
370+
* @param network The network to use
371+
* @returns Transaction details
328372
*/
329373
export async function transferERC1155(
330374
tokenAddress: Address,
331375
toAddress: Address,
332376
tokenId: bigint,
333-
amount: bigint,
334-
privateKey: `0x${string}`,
377+
amount: string,
378+
privateKey: string | `0x${string}`,
335379
network: string = 'ethereum'
336380
): Promise<{
337381
txHash: Hash;
338382
tokenId: string;
339383
amount: string;
340384
}> {
385+
// Ensure the private key has 0x prefix
386+
const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
387+
? `0x${privateKey}` as Hex
388+
: privateKey as Hex;
389+
341390
const publicClient = getPublicClient(network);
342-
const walletClient = getWalletClient(privateKey, network);
391+
const walletClient = getWalletClient(formattedKey, network);
343392
const account = walletClient.account!;
344393
const fromAddress = account.address;
345394
const chain = getChain(network);
346395

396+
// Convert amount to bigint (ERC1155 tokens typically don't have decimals)
397+
const amountBigInt = BigInt(amount);
398+
347399
// Verify balance before transfer
348400
const contract = getContract({
349401
address: tokenAddress,
@@ -352,23 +404,23 @@ export async function transferERC1155(
352404
});
353405

354406
const balance = await contract.read.balanceOf([fromAddress, tokenId]);
355-
if (balance < amount) {
356-
throw new Error(`Insufficient balance (${balance.toString()}) for transfer of ${amount.toString()} tokens with ID #${tokenId}`);
407+
if (balance < amountBigInt) {
408+
throw new Error(`Insufficient balance (${balance.toString()}) for transfer of ${amount} tokens with ID #${tokenId}`);
357409
}
358410

359411
// Send the token
360412
const hash = await walletClient.writeContract({
361413
address: tokenAddress,
362414
abi: erc1155TransferAbi,
363415
functionName: 'safeTransferFrom',
364-
args: [fromAddress, toAddress, tokenId, amount, '0x' as `0x${string}`], // empty bytes for data
416+
args: [fromAddress, toAddress, tokenId, amountBigInt, '0x' as `0x${string}`], // empty bytes for data
365417
account,
366418
chain
367419
});
368420

369421
return {
370422
txHash: hash,
371423
tokenId: tokenId.toString(),
372-
amount: amount.toString()
424+
amount: amount
373425
};
374426
}

src/core/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ export function registerEVMTools(server: McpServer) {
595595
tokenAddress as Address,
596596
toAddress as Address,
597597
BigInt(tokenId),
598-
BigInt(amount),
598+
amount,
599599
formattedKey,
600600
network
601601
);

src/index.ts

100644100755
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { config } from "dotenv";
21
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
32
import startServer from "./server/server.js";
43

5-
// Load environment variables
6-
config();
7-
84
// Start the server
95
async function main() {
106
try {

src/server/http-server.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import express, { Request, Response } from "express";
55
import cors from "cors";
66
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
77

8-
// Load environment variables
9-
config();
10-
11-
// Environment variables - choose a different port if 3000 is in use
12-
const PORT = process.env.SERVER_PORT ? parseInt(process.env.SERVER_PORT) : 3001;
13-
const HOST = process.env.SERVER_HOST || '0.0.0.0';
8+
// Environment variables - hardcoded values
9+
const PORT = 3001;
10+
const HOST = '0.0.0.0';
1411

1512
console.error(`Configured to listen on ${HOST}:${PORT}`);
1613

src/server/server.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { registerEVMResources } from "../core/resources.js";
33
import { registerEVMTools } from "../core/tools.js";
44
import { registerEVMPrompts } from "../core/prompts.js";
55
import { getSupportedNetworks } from "../core/chains.js";
6-
import dotenv from "dotenv";
7-
8-
// Load environment variables
9-
dotenv.config();
106

117
// Create and start the MCP server
128
async function startServer() {

0 commit comments

Comments
 (0)