wallet-packages
v1.0.2
Published
Multi-wallet connection library for Supra blockchain supporting Starkey and Ribbit wallets
Maintainers
Readme
wallet-packages
Multi-wallet connection library for Supra blockchain supporting Starkey and Ribbit wallets.
Installation
npm install wallet-packages
# or
yarn add wallet-packages
# or
pnpm add wallet-packagesPeer Dependencies
This package requires the following peer dependencies:
react(^18.0.0 || ^19.0.0)react-dom(^18.0.0 || ^19.0.0)
Note: Wallet icons are automatically included as base64 data URLs in the bundle, so no additional configuration is needed for images.
Usage
Basic Wallet Connection
import { ConnectWalletHandler } from 'wallet-packages';
function App() {
return (
<ConnectWalletHandler>
{({ isConnected, handleConnect, handleDisconnect, accounts, balance }) => (
<div>
{isConnected ? (
<div>
<p>Connected: {accounts[0]}</p>
<p>Balance: {balance}</p>
<button onClick={handleDisconnect}>Disconnect</button>
</div>
) : (
<button onClick={handleConnect}>Connect Wallet</button>
)}
</div>
)}
</ConnectWalletHandler>
);
}Using the Hook Directly
import { useSupraMultiWallet } from 'wallet-packages';
function MyComponent() {
const {
accounts,
balance,
connectWallet,
disconnectWallet,
sendRawTransaction,
signMessage,
loading,
} = useSupraMultiWallet();
const handleConnect = async () => {
await connectWallet('starkey'); // or 'ribbit'
};
return (
<div>
{/* Your component */}
</div>
);
}Conversion Utils
import { useConversionUtils } from 'wallet-packages';
function MyComponent() {
const {
serializeUint64,
serializeUint128,
serializeTransactionArgs,
addressToUint8Array,
} = useConversionUtils();
// Use conversion utilities
}Wallet Icons
Wallet icons are included in the package and automatically used by the ConnectWalletHandler component. You can also import them directly:
import { WALLET_ICONS, starkeyIcon, ribbitIcon } from 'wallet-packages';
// Use in your components
<img src={starkeyIcon} alt="Starkey Wallet" />
<img src={WALLET_ICONS.ribbit} alt="Ribbit Wallet" />API Reference
Components
ConnectWalletHandler
Main component for wallet connection UI.
Props:
onConnect?: (account: string) => void- Callback when wallet connectsonDisconnect?: () => void- Callback when wallet disconnectschildren: (props) => React.ReactNode- Render prop with wallet state
Children Props:
isConnected: boolean- Whether wallet is connectedaccounts: string[]- Connected account addressesloading: boolean- Loading statebalance: string- Wallet balanceuserProfile: UserProfile | null- User profile datahandleConnect: () => void- Function to trigger connection modalhandleDisconnect: () => void- Function to disconnect wallet
Hooks
useSupraMultiWallet()
Main hook for wallet functionality.
Returns:
selectedWallet: WalletType- Currently selected wallet typeaccounts: string[]- Connected accountsbalance: string- Wallet balanceconnectWallet: (walletType?: WalletType) => Promise<boolean>- Connect walletdisconnectWallet: () => Promise<void>- Disconnect walletsendRawTransaction: (...) => Promise<string>- Send raw transactionsignMessage: (...) => Promise<SignMessageResponse>- Sign messagegetAvailableWallets: () => WalletInfo[]- Get available walletsloading: boolean- Loading state
useConversionUtils()
Utility hook for data conversion and serialization.
Returns:
serializeUint8,serializeUint16,serializeUint32,serializeUint64,serializeUint128,serializeU256serializeBool,serializeVectoraddressToUint8Array,stringToUint8ArrayserializeTransactionArgs- Serialize transaction arguments from ABIfetchModuleABI- Fetch module ABI from RPCgetFunctionParamTypes- Get function parameter types
Types
type WalletType = 'starkey' | 'ribbit';
interface UserProfile {
address: string;
username: string | null;
profileImage: string | null;
}
interface ModuleABI {
address: string;
name: string;
exposed_functions: Array<{
name: string;
params: string[];
return?: string[];
}>;
// ... more fields
}Supported Wallets
- Starkey Wallet - Browser extension wallet
- Ribbit Wallet - Mobile and browser wallet
License
if i can create a package then user install tthen what they can do direclty install this depandancy ? MIT
