open-index/open-npm huggingface dataset:
npm package: @sodazone/ocelloids-client
Description: Ocelloids client library
Author: SO/DA
Latest version: 4.0.5

# Ocelloids Client Library

<a href="https://www.npmjs.com/package/@sodazone/ocelloids-client"><img src="https://img.shields.io/npm/v/@sodazone/ocelloids-client?color=69D2E7&labelColor=69D2E7&logo=npm&logoColor=333333" alt="npm @sodazone/ocelloids-client" /></a> 

TypeScript client library to interact with Ocelloids Service APIs.

[Documentation Site](https://sodazone.github.io/ocelloids-services/).

## Install

NPM
```shell
npm install @sodazone/ocelloids-client
```

Yarn
```shell
yarn add @sodazone/ocelloids-client
```

## Usage

```typescript
import { createXcmAgent } from "@sodazone/ocelloids-client";

// create an xcm agent client
const agent = createXcmAgent({
  httpUrl: "http://127.0.0.1:3000",
  wsUrl: "ws://127.0.0.1:3000"
});

// subscribe on-demand
const ws = agent.subscribe({
  senders: "*",
  events: "*",
  origins: ["urn:ocn:polkadot:2004"],
  destinations: [ 
    "urn:ocn:polkadot:0",
    "urn:ocn:polkadot:1000",
    "urn:ocn:polkadot:2000",
    "urn:ocn:polkadot:2034",
    "urn:ocn:polkadot:2104"
  ]
 }, {
  onMessage: msg => {
    if(xcm.isXcmReceived(msg)) {
      console.log("RECV", msg.subscriptionId);
    } else if(xcm.isXcmSent(msg)) {
      console.log("SENT", msg.subscriptionId)
    }
    console.log(msg);
  },
  onError: error => console.log(error),
  onClose: event => console.log(event.reason)
});
```

[Explore the documentation site for further details](https://sodazone.github.io/ocelloids-services/).

## Development

Enable corepack:

```shell
corepack enable
```

Install dependencies and build the project:

```shell
yarn && yarn build
```

## Testing

Run unit tests:

```shell
yarn test
```

Run unit tests with coverage report:

```shell
yarn test:coverage
```

## Compatibility

Compatible with [browser environments, Node and Bun](https://github.com/sodazone/ocelloids-services/blob/main/packages/client/test).
npm package: @sodazone/ocelloids-contracts
Description: Contracts pallet support.
Author: soda
Latest version: 1.2.1

# Ocelloids Contracts Module

<a href="https://www.npmjs.com/package/@sodazone/ocelloids-contracts">
  <img 
    src="https://img.shields.io/npm/v/@sodazone/ocelloids-contracts?color=69D2E7&labelColor=69D2E7&logo=npm&logoColor=333333"
    alt="npm @sodazone/ocelloids-contracts"
  />
</a>

The Ocelloids Contracts Module provides support for Substrate's contracts pallet, specifically for decoding contract messages, events, and constructors, and enables easy filtering of these elements. It is designed to be used in conjunction with the Ocelloids Core Module.

## Layout

The `packages/pallets/contracts` module source folder is structured as follows:

| Directory                    | Description                                |
|------------------------------|--------------------------------------------|
|  converters                  | Contract data type conversions             |
|  operators                   | Reactive operators for contract activities |
|  types                       | Extended contract types                    |

## Usage

Refer to the [SDK documentation](https://sodazone.github.io/ocelloids/).

### Example: Tracking Contract Events

Here is a simple example of how to track all events emitted by the [link](https://github.com/paritytech/link) contract deployed on Rococo Contracts:

```typescript
import { readFileSync } from 'node:fs';
import path from 'node:path';

import { WsProvider } from '@polkadot/api';
import { Abi } from '@polkadot/api-contract';

import {
  SubstrateApis,
  blocks
} from '@sodazone/ocelloids';

import {
  filterContractEvents,
  converters
} from '@sodazone/ocelloids-contracts';

const CONTRACT_ADDRESS = '5GdHQQkRHvEEE4sDkcLkxCCumSkw2SFBJSLKzbMTNARLTXz3';

const contractMetadataJson = readFileSync((path.resolve(__dirname, './metadata.json'))).toString();
const abi = new Abi(contractMetadataJson);

const apis = new SubstrateApis({
  rococoContracts: {
    provider: new WsProvider('wss://rococo-contracts-rpc.polkadot.io')
  }
});

apis.rx.rococoContracts.pipe(
  blocks(),
  filterContractEvents(abi, CONTRACT_ADDRESS)
).subscribe(
  x => console.log({
    ...converters.contracts.toNamedPrimitive(x),
    blockEvent: x.blockEvent.toHuman()
  })
);
```

Output:

```javascript
{
  blockEvent: {
    eventId: '2920834-2-1',
    extrinsicId: '2920834-2',
    extrinsicPosition: 1,
    blockNumber: '2,920,834',
    method: 'ContractEmitted',
    section: 'contracts',
    index: '0x2803',
    data: {
      contract: '5GdHQQkRHvEEE4sDkcLkxCCumSkw2SFBJSLKzbMTNARLTXz3',
      data: '0x00144a736d48325868747470733a2f2f6d79666162756c6f75732e75726c'
    }
  },
  event: {
    docs: [ ' A new slug mapping was created.' ],
    identifier: 'Shortened',
    index: 0
  },
  args: { slug: 'JsmH2', url: 'https://myfabulous.url' }
}
```

For more detailed examples, please refer to the [watch-contracts](https://github.com/sodazone/ocelloids/tree/main/examples/watch-contracts) example application.
npm package: @sodazone/ocelloids-sdk-contracts
Description: Contracts pallet support.
Author: soda
Latest version: 1.3.2

# Ocelloids Contracts Module

<a href="https://www.npmjs.com/package/@sodazone/ocelloids-sdk-contracts">
  <img 
    src="https://img.shields.io/npm/v/@sodazone/ocelloids-sdk-contracts?color=69D2E7&labelColor=69D2E7&logo=npm&logoColor=333333"
    alt="npm @sodazone/ocelloids-sdk-contracts"
  />
</a>

The Ocelloids Contracts Module provides support for Substrate's contracts pallet, specifically for decoding contract messages, events, and constructors, and enables easy filtering of these elements. It is designed to be used in conjunction with the Ocelloids Core Module.

## Layout

The `packages/pallets/contracts` module source folder is structured as follows:

| Directory                    | Description                                |
|------------------------------|--------------------------------------------|
|  converters                  | Contract data type conversions             |
|  operators                   | Reactive operators for contract activities |
|  types                       | Extended contract types                    |

## Usage

Refer to the [SDK documentation](https://sodazone.github.io/ocelloids-sdk/).

### Example: Tracking Contract Events

Here is a simple example of how to track all events emitted by the [link](https://github.com/paritytech/link) contract deployed on Rococo Contracts:

```typescript
import { readFileSync } from 'node:fs';
import path from 'node:path';

import { WsProvider } from '@polkadot/api';
import { Abi } from '@polkadot/api-contract';

import {
  SubstrateApis,
  blocks
} from '@sodazone/ocelloids-sdk';

import {
  filterContractEvents,
  converters
} from '@sodazone/ocelloids-sdk-contracts';

const CONTRACT_ADDRESS = '5GdHQQkRHvEEE4sDkcLkxCCumSkw2SFBJSLKzbMTNARLTXz3';

const contractMetadataJson = readFileSync((path.resolve(__dirname, './metadata.json'))).toString();
const abi = new Abi(contractMetadataJson);

const apis = new SubstrateApis({
  rococoContracts: {
    provider: new WsProvider('wss://rococo-contracts-rpc.polkadot.io')
  }
});

apis.rx.rococoContracts.pipe(
  blocks(),
  filterContractEvents(abi, CONTRACT_ADDRESS)
).subscribe(
  x => console.log({
    ...converters.contracts.toNamedPrimitive(x),
    blockEvent: x.blockEvent.toHuman()
  })
);
```

Output:

```javascript
{
  blockEvent: {
    eventId: '2920834-2-1',
    extrinsicId: '2920834-2',
    extrinsicPosition: 1,
    blockNumber: '2,920,834',
    method: 'ContractEmitted',
    section: 'contracts',
    index: '0x2803',
    data: {
      contract: '5GdHQQkRHvEEE4sDkcLkxCCumSkw2SFBJSLKzbMTNARLTXz3',
      data: '0x00144a736d48325868747470733a2f2f6d79666162756c6f75732e75726c'
    }
  },
  event: {
    docs: [ ' A new slug mapping was created.' ],
    identifier: 'Shortened',
    index: 0
  },
  args: { slug: 'JsmH2', url: 'https://myfabulous.url' }
}
```

For more detailed examples, please refer to the [watch-contracts](https://github.com/sodazone/ocelloids-sdk/tree/main/examples/watch-contracts) example application.