Skip to content

An API for rchain dapps to communicate with the blockchain

License

Notifications You must be signed in to change notification settings

rchain-community/rchain-api

Repository files navigation

RChain-API

An API for dApp frontends to communicate with the RChain blockchain.

The RChain Cooperative is developing a decentralized, economically sustainable public compute infrastructure. Decentralized applications or "dApps" will run their business logic as smart contracts on the blockchain. Their user interfaces will be more traditional programs that interact with the blockchain as a backend. This separation allows dApp developers to create nice abstract interfaces, and allows end users to create their own sovereign interfaces should they choose to do so.

Quickstart

Install with npm install rchain-community/rchain-api. Then, to get current block info from testnet:

import { RNode } = from 'rchain-api';

const obs = RNode(fetch)
  .observer('https://observer.testnet.rchain.coop');
(async () => {
  const blocks = await rnode.getBlocks(1);
  assert.ok(blocks[0].blockHash);
})();

If your node is a validator and you have a key to authorize payment, you can deploy code:

const { RNode, signDeploy } = require('rchain-api');

const val = RNode(fetch)
  .validator('https://node1.testnet.rchain-dev.tk');

const term = '@"world"!("Hello!")';
const myKey = '11'.repeat(32);
const timestamp = new Date('2019-04-12T17:59:29.274Z').valueOf();
const [recent] = await observer.getBlocks(1);
const info = signDeploy(myKey, { timestamp, term, phloLimit: 10000, phloPrice: 1, validAfterBlockNumber: recent.blockNumber });
rnode.deploy(info).then((message) => { assert(message.startsWith('Success')); });

API (OUT OF DATE)

./docs/

Getting access to an RChain node

Choices include:

Examples and Related Projects

  • Nth Caller a minimal RChain-based dApp game that uses RChain-API
  • Status a moderately complex dapp that uses more RChain-API features as well as RSign
  • Coin Faucet An advanced robust dApp that use raspberry PI to airdrop tokens to devices in physical proximity
  • RChain-dbr A web-of-trust based distributed budgeting and rewards dApp
  • RSign A chrome extension for generating client-side signatures akin to metamask
  • node-client A similar but less mature RChain API written in python

License

Copyright 2018-2019 RChain Cooperative

Apache 2.0 License (See LICENSE.txt)

Contributions welcome (See CONTRIBUTING.md)