Skip to content

Commit

Permalink
Update tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Aug 28, 2024
1 parent 6c59bb5 commit 6706dd3
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
10 changes: 5 additions & 5 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 @@ -13,7 +13,7 @@
"license": "MIT",
"dependencies": {
"dotenv": "^16.3.1",
"permissionless": "0.0.0-v0-2.20240827T152549",
"permissionless": "0.0.0-v0-2.20240828T162812",
"viem": "2.20.0"
},
"devDependencies": {
Expand Down
102 changes: 84 additions & 18 deletions tutorial-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Hex, createPublicClient, http } from "viem"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { sepolia } from "viem/chains"
import { createPimlicoClient } from "permissionless/clients/pimlico"
import { createBundlerClient, createPaymasterClient, entryPoint07Address } from "viem/account-abstraction"
import { createBundlerClient, entryPoint07Address } from "viem/account-abstraction"
import { createSmartAccountClient } from "permissionless"

const apiKey = process.env.PIMLICO_API_KEY
if (!apiKey) throw new Error("Missing PIMLICO_API_KEY")
Expand Down Expand Up @@ -49,26 +50,91 @@ const pimlicoClient = createPimlicoClient({
}
})

const smartAccountClient = createBundlerClient({
account,
chain: sepolia,
transport: http(pimlicoUrl),
paymaster: pimlicoClient,
userOperation: {
estimateFeesPerGas: async () => {
return (await pimlicoClient.getUserOperationGasPrice()).fast
},
}
})
{
const smartAccountClient = createSmartAccountClient({
account,
chain: sepolia,
bundlerTransport: http(pimlicoUrl),
paymaster: pimlicoClient,
userOperation: {
estimateFeesPerGas: async () => {
return (await pimlicoClient.getUserOperationGasPrice()).fast
},
}
})

const userOpHash = await smartAccountClient.sendUserOperation({
calls: [{
const txHash = await smartAccountClient.sendTransaction({
to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: 0n,
data: "0x1234",
}]
})

const receipt = await smartAccountClient.waitForUserOperationReceipt({hash:userOpHash})
})

console.log(`User operation included: https://sepolia.etherscan.io/tx/${txHash}`)

const txHashMultiple = await smartAccountClient.sendTransaction({
calls: [
{
to: "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc",
value: 0n,
data: "0x1234",
},
{
to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: 0n,
data: "0x1234",
}
],
})

console.log(`User operation included: https://sepolia.etherscan.io/tx/${txHashMultiple}`)
}

{
const bundlerClient = createBundlerClient({
account,
chain: sepolia,
transport: http(pimlicoUrl),
paymaster: pimlicoClient,
userOperation: {
estimateFeesPerGas: async () => {
return (await pimlicoClient.getUserOperationGasPrice()).fast
},
}
})

const userOpHash = await bundlerClient.sendUserOperation({
calls: [{
to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: 0n,
data: "0x1234",
}]
})

const receipt = await bundlerClient.waitForUserOperationReceipt({
hash: userOpHash,
})

console.log(`User operation included: https://sepolia.etherscan.io/tx/${receipt.receipt.transactionHash}`)

const txHashMultiple = await bundlerClient.sendUserOperation({
calls: [
{
to: "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc",
value: 0n,
data: "0x1234",
},
{
to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: 0n,
data: "0x1234",
}
],
})

const receipt2 = await bundlerClient.getUserOperationReceipt({
hash: txHashMultiple,
})

console.log(`User operation included: https://sepolia.etherscan.io/tx/${receipt.receipt.transactionHash}`)
console.log(`User operation included: https://sepolia.etherscan.io/tx/${receipt2.receipt.transactionHash}`)
}
2 changes: 1 addition & 1 deletion tutorial-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const smartAccountClient = createSmartAccountClient({
client: publicClient,
account,
chain: sepolia,
transport: http(pimlicoUrl),
bundlerTransport: http(pimlicoUrl),
paymaster: {
async getPaymasterData(parameters) {
const gasEstimates = await pimlicoClient.estimateUserOperationGas({
Expand Down

0 comments on commit 6706dd3

Please sign in to comment.