-
Notifications
You must be signed in to change notification settings - Fork 11
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
d90d158
commit 6b49da8
Showing
3 changed files
with
51 additions
and
1 deletion.
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,46 @@ | ||
# Add a Create a Wallet button to your appChainIds | ||
|
||
## With wagmi | ||
|
||
```tsx | ||
import { useConnect } from "wagmi"; | ||
|
||
export function WagmiCreateWalletButton() { | ||
const { connectors, connect } = useConnect(); | ||
|
||
return <button onClick={() => connect({ connector: connectors[0] })}>Create a Wallet</button>; | ||
} | ||
``` | ||
|
||
Upon successful connection, access account information via the [`useAccount`](https://wagmi.sh/react/api/hooks/useAccount) hook. | ||
|
||
## Without wagmi | ||
|
||
```tsx | ||
import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk"; | ||
|
||
const sdk = new CoinbaseWalletSDK({ | ||
appName: "My Dapp", | ||
appLogoUrl: "https://example.com/logo.png", | ||
appChainIds: [84532], | ||
}); | ||
|
||
const provider = sdk.makeWeb3Provider(); | ||
|
||
interface CreateWalletButtonProps { | ||
handleSuccess: (res: any) => void; | ||
handleError: (error: any) => void; | ||
} | ||
|
||
export function CreateWalletButton({ handleSuccess, handleError }: CreateWalletButtonProps) { | ||
const connectToSmartWallet = async () => { | ||
try { | ||
const [address] = await provider.request<string[]>({ method: "eth_requestAccounts" }); | ||
handleSuccess(address); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
}; | ||
return <button onClick={connectToSmartWallet}>Create a Wallet</button>; | ||
} | ||
``` |
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
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