Skip to content

Commit

Permalink
examples: biconomy bundler (#2663)
Browse files Browse the repository at this point in the history
* Add biconomy bundler URL

* Update bundler.md

* Update site/pages/account-abstraction.mdx

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/estimateUserOperationGas.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/getChainId.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/getSupportedEntryPoints.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/getUserOperation.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/prepareUserOperation.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/sendUserOperation.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/waitForUserOperationReceipt.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/clients/bundler.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/guides/sending-user-operations.md

Co-authored-by: awkweb <[email protected]>

* Update site/pages/account-abstraction/actions/bundler/getUserOperationReceipt.md

Co-authored-by: awkweb <[email protected]>

* Add biconomy bundler example

* chore: tweaks

* chore: format

---------

Co-authored-by: jxom <[email protected]>
Co-authored-by: awkweb <[email protected]>
Co-authored-by: jxom <[email protected]>
  • Loading branch information
4 people authored Sep 3, 2024
1 parent e857d95 commit a6576a9
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 282 deletions.
1 change: 1 addition & 0 deletions examples/account-abstraction_biconomy-bundler/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_PRIVATE_KEY=
3 changes: 3 additions & 0 deletions examples/account-abstraction_biconomy-bundler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Biconomy Bundler Example

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/wevm/viem/tree/main/examples/account-abstraction_biconomy-bundler)
20 changes: 20 additions & 0 deletions examples/account-abstraction_biconomy-bundler/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<h1>Biconomy Bundler Example</h1>
<div id="app"><button>Send User Operation</button></div>
<script type="module">
document.querySelector('button').addEventListener('click', async () => {
document.querySelector('#app').innerHTML = 'Sending...'
const response = await import('./index.ts').then((x) => x.default);
document.querySelector('#app').innerHTML = response
.map((x) => `<div style="margin-top: 16px;">${x}</div>`)
.join('');
})
</script>
</body>
</html>
59 changes: 59 additions & 0 deletions examples/account-abstraction_biconomy-bundler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { http, type Hex, createPublicClient, parseEther } from 'viem'
import {
createBundlerClient,
createPaymasterClient,
toCoinbaseSmartAccount,
} from 'viem/account-abstraction'
import { privateKeyToAccount } from 'viem/accounts'
import { sepolia } from 'viem/chains'

const client = createPublicClient({
chain: sepolia,
transport: http(),
})

const owner = privateKeyToAccount(import.meta.env.VITE_PRIVATE_KEY as Hex)

const account = await toCoinbaseSmartAccount({
client,
owners: [owner],
})

const paymasterClient = createPaymasterClient({
transport: http(
'https://paymaster.biconomy.io/api/v1/11155111/kxBB8jbLI.fb3e07cf-c4cd-4d20-8503-c396e405b0df',
),
})

const bundlerClient = createBundlerClient({
account,
client,
transport: http(
'https://bundler.biconomy.io/api/v2/11155111/kxBB8jbLI.fb3e07cf-c4cd-4d20-8503-c396e405b0df',
),
paymaster: paymasterClient,
paymasterContext: {
mode: 'SPONSORED',
calculateGasLimits: true,
expiryDuration: 300,
sponsorshipInfo: {
webhookData: {},
smartAccountInfo: {
name: 'BICONOMY',
version: '2.0.0',
},
},
},
})

const hash = await bundlerClient.sendUserOperation({
calls: [
// send 0.000001 ETH to self
{
to: account.address,
value: parseEther('0.000001'),
},
],
})

export default [`User Operation Hash: ${hash}`]
15 changes: 15 additions & 0 deletions examples/account-abstraction_biconomy-bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example-biconomy-bundler",
"private": true,
"type": "module",
"scripts": {
"dev": "vite"
},
"dependencies": {
"viem": "latest"
},
"devDependencies": {
"typescript": "^5.0.3",
"vite": "^4.4.5"
}
}
20 changes: 20 additions & 0 deletions examples/account-abstraction_biconomy-bundler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": ["src"]
}

Loading

0 comments on commit a6576a9

Please sign in to comment.