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

https://github.com/zeroxbrock/protect-button

React button that connects Metamask to Flashbots Protect when clicked
https://github.com/zeroxbrock/protect-button

Last synced: 11 months ago
JSON representation

React button that connects Metamask to Flashbots Protect when clicked

Awesome Lists containing this project

README

          

# Connect to Protect

React component: a button that connects Metamask to Flashbots Protect when clicked.

## Dependencies

* [react ^18](https://reactjs.org/)

### OPTIONAL

* [metamask-react](https://www.npmjs.com/package/metamask-react) - The component accepts a callback `addChain` given by `useMetaMask` from metamask-react to handle the low-level connection to Metamask.

## Run demo

Build from source:

```sh
cd protect
yarn install && yarn build
cd ..
```

Run demo:

```sh
cd web-demo
npm install && npm start
cd ..
```

## Using in your library

Install from npm:

```sh
yarn add protect-button
# or
npm i protect-button
```

Alternatively, if you built from source:

```sh
yarn add ../protect-button
# or
npm i ../protect-button
```

```tsx
Connect to Protect (Mainnet)
```

`addChain` is optional; if omitted, component will use `window.ethereum`

```tsx
Connect to Protect (Goerli)
```

### Full example

In a React file (tsx or jsx):

```tsx
import React from 'react'
import './App.css'
// using metamask-react is optional but recommended
import { useMetaMask } from 'metamask-react'
import ProtectButton from "protect-button"

function App() {
const { status, connect, addChain } = useMetaMask()
return (



{status === 'notConnected' && (
Connect to MetaMask
)}
{status !== 'connected' && status !== "notConnected" && (
Connecting to MetaMask...
)}
{status === 'connected' && (<>
Connect to Protect (Mainnet)
{/* addChain is optional; if ommited, will use `window.ethereum` */}
Connect to Protect (Goerli)
>)}


);
}

export default App
```