Skip to content

Commit 77541ee

Browse files
committed
fix: respect only configured chains from runtime settings
- Remove default chains behavior that was adding mainnet, polygon, etc. - Initialize WalletProvider with empty chains object instead of all viem chains - Only process chains explicitly configured in settings.chains.evm - Add logging for configured chains and warnings when no chains configured - Fixes issue where plugin was attempting to check balances for all viem chains
1 parent ef6a453 commit 77541ee

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/providers/wallet.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { SupportedChain } from '../types';
3636

3737
export class WalletProvider {
3838
private cacheKey = 'evm/wallet';
39-
chains: Record<string, Chain> = { ...viemChains };
39+
chains: Record<string, Chain> = {};
4040
account!: PrivateKeyAccount;
4141
runtime: IAgentRuntime;
4242
constructor(
@@ -45,7 +45,9 @@ export class WalletProvider {
4545
chains?: Record<string, Chain>
4646
) {
4747
this.setAccount(accountOrPrivateKey);
48-
this.addChains(chains);
48+
if (chains) {
49+
this.chains = chains;
50+
}
4951
this.runtime = runtime;
5052
}
5153

@@ -159,9 +161,8 @@ export class WalletProvider {
159161
if (!chains) {
160162
return;
161163
}
162-
for (const chain of Object.keys(chains)) {
163-
this.chains[chain] = chains[chain];
164-
}
164+
// Only add the chains that are explicitly provided
165+
this.chains = { ...this.chains, ...chains };
165166
};
166167

167168
private createHttpTransport = (chainName: SupportedChain) => {
@@ -200,17 +201,18 @@ export class WalletProvider {
200201
}
201202

202203
const genChainsFromRuntime = (runtime: IAgentRuntime): Record<string, Chain> => {
203-
// Get chains from settings or use default supported chains
204+
// Get chains from settings - ONLY use configured chains
204205
const configuredChains = (runtime?.character?.settings?.chains?.evm as SupportedChain[]) || [];
205206

206-
// Default chains to include if not specified in settings
207-
const defaultChains = ['mainnet', 'polygon', 'arbitrum', 'base', 'optimism', 'linea'];
207+
// If no chains are configured, return empty object
208+
if (configuredChains.length === 0) {
209+
elizaLogger.warn('No EVM chains configured in settings');
210+
return {};
211+
}
208212

209-
// Combine configured chains with defaults, removing duplicates
210-
const chainNames = [...new Set([...configuredChains, ...defaultChains])];
211213
const chains: Record<string, Chain> = {};
212214

213-
for (const chainName of chainNames) {
215+
for (const chainName of configuredChains) {
214216
try {
215217
// Try to get RPC URL from settings using different formats
216218
let rpcUrl = runtime.getSetting(`ETHEREUM_PROVIDER_${chainName.toUpperCase()}`);
@@ -227,6 +229,7 @@ const genChainsFromRuntime = (runtime: IAgentRuntime): Record<string, Chain> =>
227229

228230
const chain = WalletProvider.genChainFromName(chainName, rpcUrl);
229231
chains[chainName] = chain;
232+
elizaLogger.log(`Configured chain: ${chainName}`);
230233
} catch (error) {
231234
elizaLogger.error(`Error configuring chain ${chainName}:`, error);
232235
}

0 commit comments

Comments
 (0)