-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add how to use sponsorship policy with permissionless.js
- Loading branch information
1 parent
5ce1120
commit b894d06
Showing
3 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
docs/snippets/infra/platform/sponsorship-policies/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// [!region client] | ||
import { createPublicClient, http } from "viem" | ||
import { | ||
createPimlicoBundlerClient, | ||
createPimlicoPaymasterClient, | ||
} from "permissionless/clients/pimlico" | ||
import { ENTRYPOINT_ADDRESS_V07 } from "permissionless" | ||
|
||
const publicClient = createPublicClient({ | ||
transport: http("https://rpc.ankr.com/eth_sepolia"), | ||
}) | ||
|
||
const bundlerClient = createPimlicoBundlerClient({ | ||
transport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_PIMLICO_API_KEY"), | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
}) | ||
|
||
const pimlicoPaymasterClient = createPimlicoPaymasterClient({ | ||
transport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_PIMLICO_API_KEY"), | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
}) | ||
// [!endregion client] | ||
|
||
// [!region account] | ||
import { privateKeyToSimpleSmartAccount } from "permissionless/accounts" | ||
|
||
export const simpleSmartAccount = await privateKeyToSimpleSmartAccount(publicClient, { | ||
privateKey: "0xPRIVATE_KEY", | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
}) | ||
// [!endregion account] | ||
|
||
// [!region smart-account-client] | ||
import { sepolia } from "viem/chains" | ||
import { createSmartAccountClient } from "permissionless" | ||
|
||
export const smartAccountClient = createSmartAccountClient({ | ||
account: simpleSmartAccount, | ||
entryPoint: ENTRYPOINT_ADDRESS_V07, | ||
chain: sepolia, // or whatever chain you are using | ||
bundlerTransport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_PIMLICO_API_KEY"), | ||
middleware: { | ||
gasPrice: async () => { | ||
return (await bundlerClient.getUserOperationGasPrice()).fast // if using pimlico bundlers | ||
}, | ||
sponsorUserOperation: async (args) => { | ||
return pimlicoPaymasterClient.sponsorUserOperation({ | ||
...args, | ||
sponsorshipPolicyId: "sp_my_policy_id", | ||
}) | ||
}, | ||
}, | ||
}) | ||
// [!endregion smart-account-client] |