Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth committed Dec 30, 2024
1 parent 92f2564 commit 34ac4e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-evm/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const transferAction = {
callback?: HandlerCallback
) => {
console.log("Transfer action handler called");
const walletProvider = initWalletProvider(runtime);
const walletProvider = await initWalletProvider(runtime);
const action = new TransferAction(walletProvider);

// Compose transfer context
Expand Down
20 changes: 14 additions & 6 deletions packages/plugin-evm/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export class WalletProvider {
chains: Record<string, Chain> = { mainnet: viemChains.mainnet };
account: PrivateKeyAccount;

constructor(account: PrivateKeyAccount, chains?: Record<string, Chain>) {
constructor(
accountOrPrivateKey: PrivateKeyAccount | `0x${string}`,
chains?: Record<string, Chain>
) {
this.setAccount(accountOrPrivateKey);
this.setChains(chains);
this.account = account;

if (chains && Object.keys(chains).length > 0) {
this.setCurrentChain(Object.keys(chains)[0] as SupportedChain);
Expand Down Expand Up @@ -119,8 +122,14 @@ export class WalletProvider {
this.setCurrentChain(chainName);
}

private setAccount = (pk: `0x${string}`) => {
this.account = privateKeyToAccount(pk);
private setAccount = (
accountOrPrivateKey: PrivateKeyAccount | `0x${string}`
) => {
if (typeof accountOrPrivateKey === "string") {
this.account = privateKeyToAccount(accountOrPrivateKey);
} else {
this.account = accountOrPrivateKey;
}
};

private setChains = (chains?: Record<string, Chain>) => {
Expand Down Expand Up @@ -225,8 +234,7 @@ export const initWalletProvider = async (runtime: IAgentRuntime) => {
if (!privateKey) {
throw new Error("EVM_PRIVATE_KEY is missing");
}
const account = privateKeyToAccount(privateKey);
return new WalletProvider(account, chains);
return new WalletProvider(privateKey, chains);
}
};

Expand Down

0 comments on commit 34ac4e5

Please sign in to comment.