UNPKG

industry-tools

Version:

Industry Tools is a TypeScript library providing essential tools for the Industry AI Agent Platform.

40 lines (39 loc) 1.34 kB
import { ethers } from "ethers"; export async function getEVMWallet(input) { const { userId, characterId, network, storage } = input; try { const [wallet, rpc] = await Promise.all([ storage.getItem(`USER#${userId}`, `WALLET#${characterId}`), storage.getItem("RPC", `CHAIN#${network?.toUpperCase()}`) ]); if (!wallet || !wallet.privateKey) { return { error: "WalletNotFound", message: `No wallet found for character ${characterId}`, address: "", }; } if (!rpc) { return { error: "RPCNotFound", message: `No RPC found for network ${network}`, address: "", }; } const provider = new ethers.JsonRpcProvider(rpc.httpEndpoint); const signer = new ethers.Wallet(wallet.privateKey, provider); return { message: `Wallet found with address ${signer.address}`, error: "", address: signer.address, }; } catch (error) { console.log(error); return { error: "WalletError", message: `Failed to retrieve wallet data: ${error instanceof Error ? error.message : String(error)}`, address: "", }; } }