Skip to content

Commit

Permalink
fix(account): Working provider with ethers and injected wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Sep 4, 2024
1 parent 4c4e61d commit 81311ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
34 changes: 16 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@aleph-sdk/base": "file:../aleph-sdk-ts/packages/base",
"@aleph-sdk/client": "^1.0.6",
"@aleph-sdk/client": "file:../aleph-sdk-ts/packages/client",
"@aleph-sdk/core": "file:../aleph-sdk-ts/packages/core",
"@aleph-sdk/ethereum": "file:../aleph-sdk-ts/packages/ethereum",
"@aleph-sdk/evm": "file:../aleph-sdk-ts/packages/evm",
Expand Down
19 changes: 8 additions & 11 deletions src/utils/aleph-persistent-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ const LIBERTAI_SETTINGS_KEY = `${LIBERTAI_CHANNEL}-settings`;
const LIBERTAI_KNOWLEDGE_BASE_IDENTIFIERS_KEY = `${LIBERTAI_CHANNEL}-knowledge-base-identifiers-test-12`;
const LIBERTAI_KNOWLEDGE_BASE_POST_TYPE = `${LIBERTAI_CHANNEL}-knowledge-base-test-12`;

export function clientToSigner(client: Client<Transport, Chain, Account>) {
const { account, chain, transport } = client;
export function clientToProvider(client: Client<Transport, Chain, Account>) {
const { chain, transport } = client;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new providers.Web3Provider(transport, network);
const signer = provider.getSigner(account.address);
return signer;
return new providers.Web3Provider(transport, network);
}

/** Action to convert a Viem Client to an ethers.js Signer. */
export async function getEthersSigner(config: Config, { chainId }: { chainId?: number } = {}) {
/** Action to convert a Viem Client to an ethers.js Web3Provider. */
export async function getEthersProvider(config: Config, { chainId }: { chainId?: number } = {}) {
const client = await getConnectorClient(config, { chainId });
return clientToSigner(client);
return clientToProvider(client);
}

export class AlephPersistentStorage {
Expand All @@ -67,10 +65,9 @@ export class AlephPersistentStorage {
const encryptionPrivateKey = PrivateKey.fromHex(privateKey);

const subAccount = importAccountFromPrivateKey(privateKey);
const signer = await getEthersSigner(config);
const web3Provider = signer.provider;
const provider = await getEthersProvider(config);

const account = await getAccountFromProvider(web3Provider as unknown as any);
const account = await getAccountFromProvider(provider);
const accountClient = new AuthenticatedAlephHttpClient(account, process.env.ALEPH_API_URL);
const subAccountClient = new AuthenticatedAlephHttpClient(subAccount, process.env.ALEPH_API_URL);

Expand Down

0 comments on commit 81311ca

Please sign in to comment.