diff --git a/src/accounts/index.ts b/src/accounts/index.ts new file mode 100644 index 0000000..22ef648 --- /dev/null +++ b/src/accounts/index.ts @@ -0,0 +1,30 @@ +import accountFactoryAbi from "../abi/AccountFactory.abi.json" with { type: "json" }; +import { type CommunityConfig } from "../config"; +import { JsonRpcProvider, Contract } from "ethers"; + +export const getAccountAddress = async ( + config: CommunityConfig, + address: string, + salt = BigInt(0) +): Promise => { + const rpc = new JsonRpcProvider(config.primaryRPCUrl); + + const contract = new Contract( + config.community.profile.address, + accountFactoryAbi, + rpc + ); + + try { + const accountAddress = await contract.getFunction("getAccount")( + address, + salt + ); + + return accountAddress; + } catch (error) { + console.error("Error fetching account address:", error); + + return null; + } +}; diff --git a/src/index.ts b/src/index.ts index 7a8efa9..4e753c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,4 @@ export * from "./bundler"; export * from "./ipfs"; export * from "./vouchers"; export * from "./deeplink"; +export * from "./accounts"; diff --git a/src/profiles/index.ts b/src/profiles/index.ts index 8956c6f..661de1a 100644 --- a/src/profiles/index.ts +++ b/src/profiles/index.ts @@ -1,6 +1,6 @@ import { hexlify, toUtf8Bytes, JsonRpcProvider, Contract } from "ethers"; -import { type CommunityConfig } from "../index"; -import { downloadJsonFromIpfs } from "../ipfs/index"; +import { type CommunityConfig } from "../config"; +import { downloadJsonFromIpfs } from "../ipfs"; import profileContractAbi from "../abi/Profile.abi.json" with { type: "json" }; import { getEnv } from "../utils/env";