An open API service indexing awesome lists of open source software.

https://github.com/bitriel/wallet-sdk-react


https://github.com/bitriel/wallet-sdk-react

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# WalletSDK for React

## Overview

This library provides a React context and provider to easily manage blockchain wallets, contracts, and chain information using the WalletSDK core library. It simplifies the integration of blockchain functionality into React applications.

## Features

- Wallet Management: Manage wallet state and mnemonic phrases.
- Chain Management: Easily switch between different blockchain networks.
- Contract Management: Load, add, remove, and edit contracts.
- Context Integration: Utilize React context for state management and easy access across components.

## Installation

To use the WalletSDK for React, install the necessary dependencies:

```bash
npm install bitriel/wallet-sdk-react
```

## Usage

Here's an example of how to use the AccountProvider and useAccount hook in your React application:

```javascript
import React from "react";
import { AccountProvider, useAccount } from "wallet-sdk-react";

const App = () => {
return (



);
};

const MyComponent = () => {
const { account, switchChain, switchWallet, addContract } = useAccount();

return (


switchChain("https://another.chain.rpc")}>
Switch Chain

switchWallet("new mnemonic phrase")}>
Switch Wallet


addContract({
abi: yourContractAbi,
address: "0xYourContractAddress",
name: "YourContractName",
symbol: "YCN",
type: "ERC20",
chain: "mainnet",
})
}
>
Add Contract

Account Address: {account?.wallet?.address}


);
};
```

## AccountContext Interfaces

The AccountContext and AccountProvider are used to manage and provide wallet-related state and functions throughout your React application.
This context expose the following features and interfaces:

```typescript
type ContractInfo = {
abi: ethers$1.Interface | ethers$1.InterfaceAbi;
address: string;
decimal?: number;
name: string;
symbol: string;
type: string;
chain: string;
};

interface Chain {
name: string;
url: string;
symbol: string;
logo: string;
}

declare const WalletSDK: (
mnemonic: string,
chain: string,
contracts?: ContractInfo[]
) => {
balance: () => Promise;
balanceOf: (address: AddressLike) => Promise;
transfer: (
to: AddressLike,
amount: ethers$1.BigNumberish
) => Promise;
provider: ethers$1.JsonRpcProvider;
wallet: ethers$1.HDNodeWallet;
contracts: Map;
};

interface iAccountContext {
account: ReturnType | null;
switchChain?: Function;
switchWallet?: Function;
loadContract?: Function;
addContract?: Function;
removeContract: (address: string) => void;
editContract: (address: string, update: ContractInfo) => void;
chains?: Chain[];
chain: string | null;
chainInfo?: Chain;
contractsByChain: ContractInfo[];
}
```

## DevTools

To ease up development, we also provide a development widget which can serve as

- Wallet
- Contract Management and interaction similar to Remix
- Code generation
- Resizable, collapsable, dark and light mode

```javascript
import React from "react";
import { AccountProvider, WalletDevTool } from "wallet-sdk-react";

const App = () => {
return (


{/* Just insert WalletDevTool anywhere inside AccountProvider */}


);
};
```

![screenshot1!](assets/devtool1.png)
![screenshot2!](assets/devtool2.png)
![screenshot3!](assets/devtool3.png)