Skip to content

Commit

Permalink
feat: add support for fetch options when creating public clients (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Jul 19, 2023
1 parent 6f46202 commit 5028e7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
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
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
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

0 comments on commit 5028e7b

Please sign in to comment.