-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03c618b
commit 8112ce5
Showing
39 changed files
with
248 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
VITE_WALLET_CONNECT_PROJECT_ID= | ||
VITE_PIMLICO_API_KEY= |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
13 changes: 12 additions & 1 deletion
13
...count-abstraction/web3auth/pnpm-lock.yaml → ...abstraction/permissionless/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions
81
examples/account-abstraction/permissionless/src/components/Layout/Header.tsx
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,81 @@ | ||
import { CTA, Flex, Span } from '@interlay/ui'; | ||
import { useWeb3Modal } from '@web3modal/wagmi/react'; | ||
import { getSenderAddress } from 'permissionless'; | ||
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon'; | ||
import truncateEthAddress from 'truncate-eth-address'; | ||
import { concat, encodeFunctionData } from 'viem'; | ||
import { useAccount, useBalance } from 'wagmi'; | ||
import { ENTRY_POINT_ADDRESS, SIMPLE_ACCOUNT_FACTORY_ADDRESS } from '../../constants/erc4337'; | ||
import { CTAWrapper, StyledHeader } from './Layout.styles'; | ||
import { publicClient } from '../../sdk'; | ||
import { useState } from 'react'; | ||
|
||
const getInitCode = (ownerAddress: `0x${string}`) => { | ||
return concat([ | ||
SIMPLE_ACCOUNT_FACTORY_ADDRESS, | ||
encodeFunctionData({ | ||
abi: [ | ||
{ | ||
inputs: [ | ||
{ name: 'owner', type: 'address' }, | ||
{ name: 'salt', type: 'uint256' } | ||
], | ||
name: 'createAccount', | ||
outputs: [{ name: 'ret', type: 'address' }], | ||
stateMutability: 'nonpayable', | ||
type: 'function' | ||
} | ||
], | ||
args: [ownerAddress, 0n] | ||
}) | ||
]); | ||
}; | ||
|
||
const Header = () => { | ||
const { open } = useWeb3Modal(); | ||
|
||
const [smartContractAddress, setSmartContractAddress] = useState(''); | ||
|
||
const { address, isConnecting } = useAccount({ | ||
onConnect: async ({ address }) => { | ||
if (!address) return; | ||
const senderAddress = await getSenderAddress(publicClient, { | ||
initCode: getInitCode(address), | ||
entryPoint: ENTRY_POINT_ADDRESS | ||
}); | ||
|
||
setSmartContractAddress(senderAddress); | ||
} | ||
}); | ||
const { data } = useBalance({ address }); | ||
|
||
return ( | ||
<StyledHeader elementType='header' alignItems='center' justifyContent='space-between'> | ||
<a href='/' aria-label='navigate to home page'> | ||
<img | ||
src='https://uploads-ssl.webflow.com/64e85c2f3609488b3ed725f4/64ede4ad095a0a3801df095f_BobLogo.svg' | ||
width='137' | ||
alt='logo' | ||
/> | ||
</a> | ||
<CTAWrapper> | ||
<Span>{smartContractAddress}</Span> | ||
<Span>Balance: {data?.value.toString()}</Span> | ||
<CTA disabled={isConnecting} size='small' onClick={() => open()}> | ||
{address ? ( | ||
<Flex elementType='span' gap='spacing2'> | ||
<Jazzicon diameter={20} seed={jsNumberForAddress(address)} /> | ||
<Span style={{ color: 'inherit' }} size='s' color='tertiary'> | ||
{truncateEthAddress(address)} | ||
</Span> | ||
</Flex> | ||
) : ( | ||
'Connect Wallet' | ||
)} | ||
</CTA> | ||
</CTAWrapper> | ||
</StyledHeader> | ||
); | ||
}; | ||
|
||
export { Header }; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
examples/account-abstraction/permissionless/src/constants/erc4337.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,2 @@ | ||
export const ENTRY_POINT_ADDRESS = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'; | ||
export const SIMPLE_ACCOUNT_FACTORY_ADDRESS = '0x9406Cc6185a346906296840746125a0E44976454'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,48 @@ | ||
import { bundlerActions } from 'permissionless'; | ||
import { pimlicoBundlerActions, pimlicoPaymasterActions } from 'permissionless/actions/pimlico'; | ||
import { concat, createClient, createPublicClient, encodeFunctionData, http } from 'viem'; | ||
import { goerli } from 'viem/chains'; | ||
import { SIMPLE_ACCOUNT_FACTORY_ADDRESS } from './constants/erc4337'; | ||
|
||
const chain = goerli; | ||
const apiKey = import.meta.env.VITE_PIMLICO_API_KEY; // REPLACE THIS | ||
|
||
// CREATE THE CLIENTS | ||
export const publicClient = createPublicClient({ | ||
transport: http(chain.rpcUrls.default.http[0]), | ||
chain | ||
}); | ||
|
||
export const bundlerClient = createClient({ | ||
transport: http(`https://api.pimlico.io/v1/${chain.name.toLowerCase()}/rpc?apikey=${apiKey}`), | ||
chain | ||
}) | ||
.extend(bundlerActions) | ||
.extend(pimlicoBundlerActions); | ||
|
||
export const paymasterClient = createClient({ | ||
// ⚠️ using v2 of the API ⚠️ | ||
transport: http(`https://api.pimlico.io/v2/${chain.name.toLowerCase()}/rpc?apikey=${apiKey}`), | ||
chain | ||
}).extend(pimlicoPaymasterActions); | ||
|
||
export const getInitCode = (ownerAddress: `0x${string}`) => { | ||
return concat([ | ||
SIMPLE_ACCOUNT_FACTORY_ADDRESS, | ||
encodeFunctionData({ | ||
abi: [ | ||
{ | ||
inputs: [ | ||
{ name: 'owner', type: 'address' }, | ||
{ name: 'salt', type: 'uint256' } | ||
], | ||
name: 'createAccount', | ||
outputs: [{ name: 'ret', type: 'address' }], | ||
stateMutability: 'nonpayable', | ||
type: 'function' | ||
} | ||
], | ||
args: [ownerAddress, 0n] | ||
}) | ||
]); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
examples/account-abstraction/web3auth/src/components/Layout/Header.tsx
This file was deleted.
Oops, something went wrong.