# @sw3/providers

> Silvia Providers

Latest version **0.3.1** (published 2022-10-24) · AGPLv3 license · 0 weekly downloads

## Install

```sh
npm install @sw3/providers
pnpm add @sw3/providers
yarn add @sw3/providers
bun add @sw3/providers
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2022-10-24 |
| First published | 2022-08-11 |
| Weekly downloads | 0 |
| License | AGPLv3 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 80.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | cutsin |

## Links

- npm: https://www.npmjs.com/package/@sw3/providers
- Homepage: https://github.com/shuziyuansheng
- npm.io page: https://npm.io/package/@sw3/providers

## Dependencies (3)

- [@ethersproject/networks](https://npm.io/package/@ethersproject/networks.md) ^5.7.1
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.7.1
- [@ethersproject/properties](https://npm.io/package/@ethersproject/properties.md) ^5.7.0

## Recent versions

- 0.3.1 (latest) — 2022-10-24
- 0.3.0 — 2022-10-08
- 0.2.1 — 2022-08-26
- 0.1.3 — 2022-08-11

## README

# Silvia Web 3 Providers

A Web based crypto wallet to connect Silvia Blockchain apps.

You can use it to connect to the [Silvia.link](https://scan.silvia.link) blockchain network and sign transactions without a private key.

## Usage

```typescript
import { WebSocketProvider, JsonRpcProvider } from '@sw3/providers'
import { Contract } from '@ethersproject/contracts'
// Provider
const provider = new WebSocketProvider('wss://rpc.silvia.link/ws')
// Signer
const account = await provider.send('eth_requestAccounts')
const contract = new Contract(contractAddress, abi, provider.getSigner(account))
```

## Account Caching

If you're using a reactive framework like vue/react, you can maintain the state by yourself:

```typescript
const provider = new WebSocketProvider('wss://rpc.silvia.link/ws')
const state = { account: provider.account }
provider.SW3.on('accountsChanged', () => {
	state.account = provider.account
})
```

By default, SW3 caches account address using sessionStorage (`provider.SW3.account`) in convenience, you can disable it by changing the option setting to `{cache: false}`. eg:

```typescript
const provider = new WebSocketProvider('wss://rpc.silvia.link/ws', undefined, { cache: false })
```

## Provider API

| Method                    | Description                    |
| :------------------------ | :----------------------------- |
| ✅ eth_requestAccounts    | _Ethereum JSON-RPC compatible_ |
| ✅ eth_accounts           | _Ethereum JSON-RPC compatible_ |
| ✅ eth_disconnect         | _Ethereum JSON-RPC compatible_ |
| ❌ personal_sign          | _Ethereum JSON-RPC compatible_ |
| ❌ eth_sign               | _Ethereum JSON-RPC compatible_ |
| ❌ eth_signTypedData_v4   | _Ethereum JSON-RPC compatible_ |
| ❌ personal_unlockAccount | _Ethereum JSON-RPC compatible_ |
| ✅ sw3_sign               | SW3 singer                     |

| Events             | Description           |
| :----------------- | :-------------------- |
| ✅ accountsChanged | _MetaMask compatible_ |
| ✅ disconnect      | _MetaMask compatible_ |
| ✅ connect         | _MetaMask compatible_ |
| ✅ sw3_noLogin     | SW3 Event             |

---
_Source: https://npm.io/package/@sw3/providers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
