Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for fetch options when creating public clients #59

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"prebuild": "ts-node-esm inject-version",
"prebuild": "ts-node-esm ./inject-version.ts",
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/client/create-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type HttpTransport,
type PublicClient,
type Transport,
type HttpTransportConfig,
} from "viem";
import type {
EIP1193RequestFn,
Expand Down Expand Up @@ -125,16 +126,20 @@ export const createPublicErc4337FromClient: <
export const createPublicErc4337Client = ({
chain,
rpcUrl,
fetchOptions,
}: {
chain: Chain;
rpcUrl: string;
fetchOptions?: HttpTransportConfig["fetchOptions"];
}): PublicErc4337Client<HttpTransport> => {
const client = createPublicErc4337FromClient(
createPublicClient({
chain,
transport: http(rpcUrl, {
fetchOptions: {
...fetchOptions,
headers: {
...fetchOptions?.headers,
"Alchemy-AA-Sdk-Version": VERSION,
},
},
Expand Down
8 changes: 6 additions & 2 deletions packages/ethers/src/provider-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import { AccountSigner } from "./account-signer.js";
/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */
export class EthersProviderAdapter extends JsonRpcProvider {
readonly accountProvider: SmartAccountProvider<HttpTransport>;
constructor(rpcUrl: string, entryPointAddress: Address, chainId: number) {
constructor(
rpcProvider: string | PublicErc4337Client<HttpTransport>,
entryPointAddress: Address,
chainId: number
) {
super();
const chain = getChain(chainId);
this.accountProvider = new SmartAccountProvider(
rpcUrl,
rpcProvider,
entryPointAddress,
chain
);
Expand Down