File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import {
2020 createClientUPProvider ,
2121 type UPClientProvider ,
2222} from "@lukso/up-provider" ;
23- import { createWalletClient , custom } from "viem" ;
23+ import { createPublicClient , createWalletClient , custom } from "viem" ;
2424import { lukso , luksoTestnet } from "viem/chains" ;
2525import {
2626 createContext ,
@@ -85,6 +85,16 @@ export function UpProvider({ children }: UpProviderProps) {
8585 return null ;
8686 } , [ chainId ] ) ;
8787
88+ const readClient = useMemo ( ( ) => {
89+ if ( provider && chainId ) {
90+ return createPublicClient ( {
91+ chain : chainId === 42 ? lukso : luksoTestnet ,
92+ transport : custom ( provider ) ,
93+ } ) ;
94+ }
95+ return null ;
96+ } , [ chainId ] ) ;
97+
8898 useEffect ( ( ) => {
8999 let mounted = true ;
90100
@@ -99,7 +109,9 @@ export function UpProvider({ children }: UpProviderProps) {
99109 if ( ! mounted ) return ;
100110 setAccounts ( _accounts ) ;
101111
102- const _chainId = ( await provider . request ( "eth_chainId" ) ) as number ;
112+ const _chainId = Number (
113+ ( await provider . request ( "eth_chainId" ) ) as string
114+ ) ;
103115 if ( ! mounted ) return ;
104116 setChainId ( _chainId ) ;
105117
@@ -156,6 +168,7 @@ export function UpProvider({ children }: UpProviderProps) {
156168 provider,
157169 client,
158170 chainId,
171+ readClient,
159172 accounts,
160173 contextAccounts,
161174 walletConnected,
@@ -167,6 +180,7 @@ export function UpProvider({ children }: UpProviderProps) {
167180 } , [
168181 client ,
169182 chainId ,
183+ readClient ,
170184 accounts ,
171185 contextAccounts ,
172186 walletConnected ,
You can’t perform that action at this time.
0 commit comments