(E2 Solution): Migrate dApp to dApp Kit React with SDK v2#121
(E2 Solution): Migrate dApp to dApp Kit React with SDK v2#121
Conversation
|
Note: Pointing to solution folder |
|
okay all good, I updated this for using tailwind and not the old css components, ready to review and merge |
domenicodev
left a comment
There was a problem hiding this comment.
Not a bad idea to showcase different refreshing logics, but for this module it wouldn't be needed and would add complexity, as we'll also explain it the "tanstack way" and "invalidateQueries" way (also included in quizzes).
We might consider alternatives in the future but not for the moment, so please take a look at the comments carefully to switch back to the default way
|
I'm rather confused with the tanstack query thing https://sdk.mystenlabs.com/sui/migrations/sui-2.0/dapp-kit#removing-tanstack-query |
|
It says "if you were using it only for dapp-kit and nothing else, you can remove" But still they're using it in the boilerplate from create-dapp, possibly for helping migrating quickly, so if you remove it you still have to edit "OwnedObjects.tsx" anyway, and remove useQuery logic; The alternative would be doing something like you(or claude?) did, with ad-hoc refreshing, but still tanstack is the good way to go, and included in the main boilerplate |
|
@domenicodev it was team work actually, claude didn't touch the tanstack query part but since I didn't really understand how it worked and saw the migration bit about this, I insisted claude on getting rid of tanstack for good :/ |
Summary
@mysten/dapp-kit+ JSON-RPC) to SDK v2 (@mysten/dapp-kit-react+ gRPC)QueryClientProvider+SuiClientProvider+WalletProvider) with a singleDAppKitProviderpowered bycreateDAppKit()factorySuiClient(JSON-RPC) withSuiGrpcClient(gRPC/protobuf) for node communication@tanstack/react-queryfor data fetching —useQuerywraps the gRPC client, andinvalidateQuerieshandles real-time UI refresh after mutations (consistent withcreate-dappboilerplate)useSuiClientQuery→useQuery+useCurrentClient(),useSignAndExecuteTransaction→useDAppKit().signAndExecuteTransaction()declare module "@mysten/dapp-kit-react") for type-safe hook returns@mysten/dapp-kit/dist/index.csswith Tailwind CSS v4 for stylingE2/README.mdas a step-by-step educational guide covering the new dApp Kit API.gitignoreto exclude build artifacts and.pnpmdirectoryKey migration patterns demonstrated
@mysten/dapp-kit@mysten/dapp-kit-reactSuiClientfrom@mysten/sui/clientSuiGrpcClientfrom@mysten/sui/grpccreateNetworkConfig()createDAppKit()withdeclare moduleaugmentationSuiClientProvider+WalletProvider+QueryClientProviderQueryClientProvider+DAppKitProvideruseSuiClientQuery("getOwnedObjects", ...)useQuery()+useCurrentClient().listOwnedObjects()useSignAndExecuteTransaction()hookuseDAppKit().signAndExecuteTransaction()getFullnodeUrl("testnet")baseUrl:param@mysten/dapp-kit/dist/index.cssqueryClient.invalidateQueries()with predicate matchingData fetching approach
Since
@mysten/dapp-kit-reactv1.x does not exportuseSuiClientQuery, TanStack Query is added as a standalone dependency. Each data-fetching component usesuseQuerywith semantic query keys ([network, "getOwnedObjects", address]), and mutations triggerinvalidateQuerieswith a predicate matcher — keeping the same caching and auto-refresh pattern used increate-dapp.Test plan
pnpm installsucceeds inE2/my-first-sui-dapp/pnpm run buildcompiles without errorssui-2-migration-auditskill — 19 PASS, 0 FAIL, 13 N/A)invalidateQueries🤖 Generated with Claude Code