yeezy-wallet-sdk
v0.4.0
Published
A wallet SDK for Yeezy
Maintainers
Readme
Yeezy Wallet SDK
A wallet SDK for Yeezy, providing React components and utilities for wallet integration.
Example
cd example
npm install
npm run dev
publish
npm login
npm publishUsage
1. Login
- Add context to the root
import { WalletProvider, Network } from "yeezy-wallet-sdk";
const BASE_URL =
process.env.NEXT_PUBLIC_WALLET_BASE_URL;
const SOLANA_RPC_URL =
process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
...
<html>
<body>
<WalletProvider
config={{
baseURL: BASE_URL,
solanaCluster: {
name: "mainnet-beta",
rpcUrl: SOLANA_RPC_URL,
},
defaultNetwork: Network.Solana,
}}
>
{children}
</WalletProvider>
</body>
</html>- Connect wallet
import { useActiveWallet, useConnect } from "yeezy-wallet-sdk";
...
const { wallet } = useActiveWallet();
const { disconnect, connect } = useConnect();
const walletAddress = wallet?.solanaAddress ?? ""; // get address
const handleLogout = () => {
disconnect()
};
const handleLogin = () => {
connect()
}2. Sign transaction and send transaction
import { useActiveWallet, useConnect } from "yeezy-wallet-sdk";
const { wallet: activeWallet } = useActiveWallet();
...
// construct the transaction
const transaction = new Transaction()
// sign and send transaction
const signed = await activeWallet.signSolanaTransaction(transaction);
const signature = await activeWallet.sendSolanaTransaction(
signed.serialize()
);
const latestBlockHash = await connection.getLatestBlockhash();
// wait for transaction to be confirmed
await confirmTransaction(
{
signature,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
},
"confirmed"
);
3. Use coinbase onramp to buy crypto token
import { useCoinbaseOnramp } from 'yeezy-wallet-sdk'
...
const {getCoinbaseOnrampUrl} = useCoinbaseOnramp()
const handleCoinbaseOnramp = async() => {
const url = async getCoinbaseOnrampUrl()
if(url) {
window.open(url,'_blank'); //go to Coinbase onramp flow
}
}
