1.8.1 • Published 1 year ago

@open-rpc/client-js v1.8.1

Weekly downloads
279
License
Apache-2.0
Repository
github
Last release
1 year ago

OpenRPC Client JS

A browser-compatible JSON-RPC client with multiple transports:

  • EventEmitter
  • HTTP/HTTPS
  • WebSocket
  • PostMessageWindow
  • PostMessageIframe
import { RequestManager, HTTPTransport, Client } from "@open-rpc/client-js";
const transport = new HTTPTransport("http://localhost:8545");
const client = new Client(new RequestManager([transport]));
const result = await client.request({method: "addition", params: [2, 2]});
// => { jsonrpc: '2.0', id: 1, result: 4 }

Examples

import { EventEmitter } from "events";
import { RequestManager, EventEmitterTransport, Client } from "@open-rpc/client-js";

const chan1 = "chan1";
const chan2 = "chan2";

const emitter = new EventEmitter();
const transport = new EventEmitterTransport(emitter, chan1, chan2);
const requestManager = new RequestManager([transport]);
const client = new Client(requestManager);

// event emitter server code
emitter.on(chan1, (jsonrpcRequest) => {
  const res = {
    jsonrpc: "2.0",
    result: "potato",
    id: jsonrpcRequest.id,
  };
  emitter.emit(chan2, JSON.stringify(res));
});

const main = async () => {
  const result = await client.request({method: "addition", params: [2, 2]});
  console.log(result);
};

main().then(() => {
  console.log("DONE");
});
import { RequestManager, Client, HTTPTransport } from "@open-rpc/client-js";

const transport = new HTTPTransport("http://localhost:3333");
const requestManager = new RequestManager([transport]);
const client = new Client(requestManager);

const main = async () => {
  const result = await client.request({method: "addition", params: [2, 2]});
  console.log(result);
};

main().then(() => {
  console.log("DONE");
});
import { RequestManager, Client, WebSocketTransport } from "@open-rpc/client-js";

const transport = new WebSocketTransport("ws://localhost:3333");
const requestManager = new RequestManager([transport]);
const client = new Client(requestManager);

const main = async () => {
  const result = await client.request({method: "addition", params: [2, 2]});
  console.log(result);
};

main().then(() => {
  console.log("DONE");
  client.close();
});

Contributing

How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.

casper-js-sdk-test-h2hdwalletcoinoxscasperdask-js-sdk@infinitebrahmanuniverse/nolb-_open-@everything-registry/sub-chunk-684headsup-serverheadsup-server-clienthsuijs@benfen/bfc.js@ckitjs/mercury-client@ckitjs/tippy-client@clangd-wasm/clangd-wasm@databutton/codemirror-languageserver@colligence/aws-kms-provider@djhahe/casperdash-js-sdk@etherdata-blockchain/etherdata-sdk-react@ethernode/ethernode-enapi-client@ethernodeio/enapi-client@etclabscore/pristine-typescript-openrpc-server-client@etclabscore/signatory@etclabscore/signatory-client@etclabscore/ethereum-json-rpc@etclabscore/jade-service-runner@etclabscore/jade-service-runner-client@geosky/gsaapi-client@heemale/mango.js@gdquest/codemirror-gdscript@jiffy-labs/web3aetd-react-uietherdata-react-uiethos-connectethereum-json-rpc-typesfishyfishkevacoin-jskardia-js-sdkradixdlt-js-sdksig.tools-sdkstarknet-account-analyzerstarknet-rpc-providertest-sui.js@abstractfruitfactory/radix-js@kyve/octopus@levihhh/sui.js@marimo-team/frontend@marimo-team/frontend-wasm@marimo-team/islands@massalabs/massa-web3@martianwallet/sui-web3.js@roochnetwork/rooch-sdk@roochnetwork/sdk@radixdlt/networking@owodunni/inspector@open-rpc/inspector@planetarium/aws-kms-provider@mgonetwork/mango.js@shadowtest/octopus-backup@shadowtest/polkadot-backup@shadowtest/polkadot-backup-ex@shinami/clients@shipsgold/ships-client@shipsgold/ships-contracts-client@swappland/ft-standards-client@swappland/market-contract-client@swappland/market-contract-spec@swappland/nft-standards-client@swappland/open-rpc-token-standards-specs@swappland/simple-ft-client@swappland/simple-nft-client@swappland/wallet-indexer-api-clientaws-kms-provider@urbit/roller-api@zalastax/nolb-_open-@yubing744/rooch-sdk@toruslabs/xrpl-controllers@tokesim/tokesim-chain@toruslabs/casper-js-sdk@zhujiantao/inspector@usedapptesthello/casper-js-sdk@xops.net/inspector-snaps@xops.net/openrpc-clicasperdash-js-sdkcasper-client-sdkcasper-js-sdkcasper-js-sdk-testcasper-js-sdk-test2dimension-js-sdkdimension-js-sdk-cycolligence-aws-kms-providercodemirror-languageservercremona
1.8.1

1 year ago

1.8.0

1 year ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago