|
| 1 | +# `@ai16z/plugin-bnb` |
| 2 | + |
| 3 | +This plugin enables interaction with the BNB Chain ecosystem, providing support for BNB Smart Chain, opBNB, and BNB Greenfield networks. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +### Default Setup |
| 10 | + |
| 11 | +By default, **plugin-bnb** is not enabled. To use it, simply add your private key and public key to the `.env` file: |
| 12 | + |
| 13 | +```env |
| 14 | +BNB_PRIVATE_KEY=your-private-key-here |
| 15 | +BNB_PUBLIC_KEY=your-public-key-here |
| 16 | +``` |
| 17 | + |
| 18 | +### Custom RPC URLs |
| 19 | + |
| 20 | +By default, the RPC URL is inferred from the `viem/chains` config. To use custom RPC URLs, add the following to your `.env` file: |
| 21 | + |
| 22 | +```env |
| 23 | +BSC_PROVIDER_URL=https://your-custom-bsc-rpc-url |
| 24 | +OPBNB_PROVIDER_URL=https://your-custom-opbnb-rpc-url |
| 25 | +``` |
| 26 | + |
| 27 | +## Provider |
| 28 | + |
| 29 | +The **Wallet Provider** initializes with BSC as the default. It: |
| 30 | + |
| 31 | +- Provides the **context** of the currently connected address and its balance. |
| 32 | +- Creates **Public** and **Wallet clients** to interact with the supported chains. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Actions |
| 37 | + |
| 38 | +### Get Balance |
| 39 | + |
| 40 | +Get the balance of an address on BSC. Just specify the: |
| 41 | + |
| 42 | +- **Chain** |
| 43 | +- **Address** |
| 44 | +- **Token** |
| 45 | + |
| 46 | +**Example usage:** |
| 47 | + |
| 48 | +```bash |
| 49 | +Get the USDC balance of 0x1234567890 on BSC. |
| 50 | +``` |
| 51 | + |
| 52 | +### Transfer |
| 53 | + |
| 54 | +Transfer tokens from one address to another on BSC/opBNB. Just specify the: |
| 55 | + |
| 56 | +- **Chain** |
| 57 | +- **Token** |
| 58 | +- **Amount** |
| 59 | +- **Recipient Address** |
| 60 | +- **Data**(Optional) |
| 61 | + |
| 62 | +**Example usage:** |
| 63 | + |
| 64 | +```bash |
| 65 | +Transfer 1 BNB to 0xRecipient on BSC. |
| 66 | +``` |
| 67 | + |
| 68 | +### Swap |
| 69 | + |
| 70 | +Swap tokens from one address to another on BSC. Just specify the: |
| 71 | + |
| 72 | +- **Input Token** |
| 73 | +- **Output Token** |
| 74 | +- **Amount** |
| 75 | +- **Chain** |
| 76 | +- **Slippage**(Optional) |
| 77 | + |
| 78 | +**Example usage:** |
| 79 | + |
| 80 | +```bash |
| 81 | +Swap 1 BNB to USDC on BSC. |
| 82 | +``` |
| 83 | + |
| 84 | +### Bridge |
| 85 | + |
| 86 | +Bridge tokens from one chain to another on BSC/opBNB. Just specify the: |
| 87 | + |
| 88 | +- **From Chain** |
| 89 | +- **To Chain** |
| 90 | +- **From Token** |
| 91 | +- **To Token** |
| 92 | +- **Amount** |
| 93 | +- **Recipient Address**(Optional) |
| 94 | + |
| 95 | +**Example usage:** |
| 96 | + |
| 97 | +```bash |
| 98 | +Bridge 1 BNB from BSC to opBNB. |
| 99 | +``` |
| 100 | + |
| 101 | +### Stake |
| 102 | + |
| 103 | +Perform staking operations on BSC through [Lista Dao](https://lista.org/liquid-staking/BNB). User will receive sliBNB(0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B) as staking credit. Just specify the: |
| 104 | + |
| 105 | +- **Action** |
| 106 | +- **Amount** |
| 107 | + |
| 108 | +**Example usage:** |
| 109 | + |
| 110 | +```bash |
| 111 | +Deposit 1 BNB to Lista Dao. |
| 112 | +``` |
| 113 | + |
| 114 | +### Faucet |
| 115 | + |
| 116 | +Request testnet tokens from the faucet. You could request any of the supported tokens(BNB, BTC, BUSD, DAI, ETH, USDC). Just specify the: |
| 117 | + |
| 118 | +- **Token**(Optional) |
| 119 | +- **Recipient Address** |
| 120 | + |
| 121 | +The recipient address must maintain a minimum balance of 0.002 BNB on BSC Mainnet to qualify. |
| 122 | + |
| 123 | +**Example usage:** |
| 124 | + |
| 125 | +```bash |
| 126 | +Get some testnet USDC from the faucet. |
| 127 | +``` |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## Contribution |
| 132 | + |
| 133 | +The plugin contains tests. Whether you're using **TDD** or not, please make sure to run the tests before submitting a PR. |
| 134 | + |
| 135 | +### Running Tests |
| 136 | + |
| 137 | +Navigate to the `plugin-bnb` directory and run: |
| 138 | + |
| 139 | +```bash |
| 140 | +pnpm test |
| 141 | +``` |
0 commit comments