Skip to content

Commit

Permalink
feat: readme for @deficonnect/provider
Browse files Browse the repository at this point in the history
  • Loading branch information
andybin-cdc committed May 24, 2022
1 parent cf598d9 commit 6ae5474
Showing 1 changed file with 25 additions and 44 deletions.
69 changes: 25 additions & 44 deletions packages/provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,47 @@
### use npm package manager

```bash
npm install "deficonnect"
npm install "@deficonnect/provider"
```

### use script tag

```html
<script type="module" src="https://unpkg.com/deficonnect/dist/index.umd.js"></script>
<script type="module" src="https://unpkg.com/@deficonnect/provider/dist/index.umd.js"></script>
```

the global variable is: `window.DeFiConnect`
the global variable is: `DeFiConnectProvider`

### constructor

```javascript
const connector = new window.DeFiConnect.DeFiWeb3Connector({
supportedChainIds: [1],
rpc: { 1: 'https://mainnet.infura.io/v3/INFURA_API_KEY' },
pollingInterval: 15000
const provider = new DeFiConnectProvider({
appName: 'your app name'
chainType: 'eth'
chainId: '28' // for eth is 1
rpcUrls: {
1: 'https://mainnet.infura.io/v3/INFURA_API_KEY',
28: 'https://evm-cronos.crypto.org/',
}
})
```

## Usage

### connect wallet

> if you use `web3-react`, it is easy to integrate:
> `DeFiWeb3Connector` has implement `AbstractConnector` from `web3-react`
```tsx
import { DeFiWeb3Connector } from 'deficonnect'
### methods for DeFiConnectProvider

const connector = new DeFiWeb3Connector({
supportedChainIds: [1],
rpc: { 1: 'https://mainnet.infura.io/v3/INFURA_API_KEY' },
pollingInterval: 15000
})
connector.activate()
```

### methods for DeFiWeb3Connector
this is a eip-1193 compatible provider.
more detail info: https://eips.ethereum.org/EIPS/eip-1193

```typescript
// connect to the Wallet
await connector.activate()
interface RequestArguments {
method: string;
params?: unknown[] | object;
}

// disconnect the Wallet
await connector.deactivate()
// Send JSON RPC requests
const result = await provider.request(payload: RequestArguments);

// Close provider session
await provider.disconnect()
```

### events for Provider (EIP-1193)
Expand All @@ -76,21 +72,6 @@ provider.on('disconnect', (code: number, reason: string) => {
})
```

### methods for Provider

```typescript
interface RequestArguments {
method: string;
params?: unknown[] | object;
}

// Send JSON RPC requests
const result = await provider.request(payload: RequestArguments);

// Close provider session
await provider.disconnect()
```

### methods for Web3

```typescript
Expand Down

0 comments on commit 6ae5474

Please sign in to comment.