# darwinia-storage

> A library to help fetch substrate storages via evm json-rpc `eth.call`

Latest version **1.1.3** (published 2022-12-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install darwinia-storage
pnpm add darwinia-storage
yarn add darwinia-storage
bun add darwinia-storage
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2022-12-13 |
| First published | 2022-12-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Aki Wu |
| Maintainers | aki.wu |
| Keywords | substrate, darwinia, storage, evm |

## Links

- npm: https://www.npmjs.com/package/darwinia-storage
- Repository: https://github.com/darwinia-network/darwinia-storage
- Homepage: https://github.com/darwinia-network/darwinia-storage#readme
- Issues: https://github.com/darwinia-network/darwinia-storage/issues
- npm.io page: https://npm.io/package/darwinia-storage

## Dependencies (2)

- [ethers](https://npm.io/package/ethers.md) ^5.7.2
- [@polkadot/types](https://npm.io/package/@polkadot/types.md) ^9.9.4

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2022-12-13
- 1.1.2 — 2022-12-13
- 1.1.1 — 2022-12-12
- 1.1.0 — 2022-12-12
- 1.0.3 — 2022-12-04
- 1.0.2 — 2022-12-02
- 1.0.1 — 2022-12-02
- 1.0.0 — 2022-12-02

## README

# darwinia-storage

A library to help fetch internal substrate storages via ethereum json-rpc `eth.call`.

You can use this lib to fetch all Darwinia storages allowed by [StateStorage precompile](https://docs.darwinia.network/builder/solidity-precompiles).

## Install
```shell
npm install darwinia-storage --save
```

## Usage

The returns of this lib's functions are all json string or null.


```typescript
import {ethers} from "ethers";
import { getStorage, buildCrabClient } from "darwinia-storage";

async function main(): Promise<void> {
    // web3 provider(eth compatible api endpoint)
    const provider = new ethers.providers.JsonRpcProvider("https://darwinia-crab.api.onfinality.io/public/");

    // read from file or network(see the curl command below)
    const crabMetadataStatic = "0x...";

    // a general storage function for a specific chain
    const getCrabStorage = getStorage(provider, crabMetadataStatic);

    // There are two ways to fetch a storage.
    //
    //  1. use storage specific functions predefined in this lib.
    const crab = buildCrabClient(getCrabStorage);
    let result = await crab.bridgeDarwiniaMessages.outboundMessages(
        {
            laneId: "0x00000000",
            nonce: 10
        } // input has one item for map which is a struct:
    );
    console.log(`${result}\n`);

    //  2. the general way.
    result = await getCrabStorage(
        "BridgeDarwiniaMessages", 
        "OutboundMessages",
        {
            laneId: "0x00000000",
            nonce: 10
        }
    );
    console.log(`${result}\n`);
}

main();
```
more examples in [examples.ts](./examples.ts)

### Get the metadata static hex string from darwinia node
```shell
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{"jsonrpc":"2.0","id":"1","method":"state_getMetadata","params":[]}' \
     https://darwinia-crab.api.onfinality.io/public/
```

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