Skip to content

Commit

Permalink
fetch account address
Browse files Browse the repository at this point in the history
  • Loading branch information
kevtechi committed Nov 10, 2024
1 parent a41440e commit d8b7c17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> => {
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;
}
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./bundler";
export * from "./ipfs";
export * from "./vouchers";
export * from "./deeplink";
export * from "./accounts";
4 changes: 2 additions & 2 deletions src/profiles/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down

0 comments on commit d8b7c17

Please sign in to comment.