Usage docs Reference Examples

Function

Static Public Summary
public

addContract(contractName: *, abi: *, networks: *): ReduxThunk

Load a contract (binding it to an web3js Contract instance), and add it to the redux store.

public

addLocalAcount(address: *): ReduxThunk

Add an account to track locally.

public

* awaitCall(callPromise: *, callID: *): Promise

Awaits a web3 call, and fires the corresponding redux events

public

* blocksSaga(web3: *, getBlocksState: ReduxStateSelector): ReduxSaga

Handles ReDApp block background processing.

public

cacheCall(options: *): ReduxThunk

Start a new call, but try to hit the cache for an existing call result first.

public

* callsSaga(web3: *, getCallsState: ReduxStateSelector): ReduxSaga

Handles ReDApp call background processing.

public

* contractsSaga(web3: *, defaultNetworkId: *, getContractsState: ReduxStateSelector): ReduxSaga

Handles ReDApp contract background processing, e.g.

public

createTransactionPromiEvent(web3: *, txID: *, txParams: *): PromiEvent<TransactionReceipt>

Web3 returns a "promise combined with an event emitter": we map this to redux events.

public

Update the list of wallet accounts.

public

forceCall(options: *): ReduxThunk

Start a new call, ignoring previous call data, forcing an overwrite when getting the result.

public

forgetCall(callID: *): ReduxThunk

Remove a call from the tracking system.

public

forgetContract(contractName: *): ReduxThunk

Removes the contract from the local redux store.

public

Forget local account.

public

forgetTX(txID: *): ReduxThunk

Remove a transaction from the tracking system.

public

Get data (like the balance) for each account in the tracker

public

getBalance(address: *): ReduxThunk

To start updating the balance of an account

public

getBlock(blockHandle: *): ReduxThunk

Get a specific block.

public

Force retrieval of the latest block.

public

Get data for an individual account.

public

* getSpecificBlock(web3: *, action: *): ReduxSaga

public

initWeb3(fallback: *): *

Initializes web3 in a fairly standard way.

public

initiateCall(web3: *, callID: *, blockNr: *, callParams: *): Promise

Initiate a web3 call, it starts waiting for a promise that is mapped to our redux call system.

public

mappedreducer(mapping: *, initialState: *): Function

Creates a simple reducer, based on a mapping and an initial state.

public

openTxChannel(promiEvent: *, txID: *): Channel<any>

Open a TX channel: this channel maps web3 events to our redux tracking system.

public

poller(startAT: *, stopAT: *, workerInner: *, errorHandler: *, workerArgs: *): pollWatcher

Simple redux saga utility for polling.

public

* saga(web3: *, defaultNetworkId: *, getRootState: *): ReduxSaga

Forks to tracking and contracts saga.

public

sendTX(options: *): ReduxThunk

Send a transaction, which will be tracked in the ReDApp tracking system.

public

Start polling for accounts.

public

Start listening for block headers, a new header will trigger the retrieval of the latest block.

public

Start polling blocks.

public

Stop polling for accounts.

public

Stop listening for block headers.

public

Stop polling blocks.

public

subber(startAT: *, stopAT: *, dataAT: *, changedAT: *, errorAT: *, openEventSub: *): subscriptionWatcher

Maps an event-emitter (like web3.js uses) to a redux-saga event-channel, with support for being started/stopped/resumed.

public

* trackingSaga(web3: *, getTrackingState: ReduxStateSelector): ReduxSaga

Forks to tracking and contracts saga.

public

* transactionsSaga(web3: *, getTransactionsState: ReduxStateSelector): ReduxSaga

Handles ReDApp transaction background processing.

Static Public

public addContract(contractName: *, abi: *, networks: *): ReduxThunk source

import {addContract} from 'redapp/es/contracts/actions/index.js'

Load a contract (binding it to an web3js Contract instance), and add it to the redux store. The methods of the contract are also added to the store, which can be called with their ABI arguments. This produces a thunk and an ID, the thunk can then be dispatched to execute the method, and the ID can be used to track the progress.

Params:

NameTypeAttributeDescription
contractName *

The name of the contract, to use as key in the store. Any contract with the same name will be overwritten.

abi *

The ABI spec (decoded object, not encoded as string). All the methods in the spec will be loaded as call/send thunk creators. (i.e. cacheCall/forceCall/trackedSend)

networks *

The network spec, like formatted by tools like truffle. An object, with network IDs (strings) as keys, and each value being an object with an "address" property.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public addLocalAcount(address: *): ReduxThunk source

import {addLocalAcount} from 'redapp/es/tracking/accounts/actions/index.js'

Add an account to track locally. (i.e. no interaction with the user)

Params:

NameTypeAttributeDescription
address *

The address of the account to start tracking.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public * awaitCall(callPromise: *, callID: *): Promise source

Awaits a web3 call, and fires the corresponding redux events

Params:

NameTypeAttributeDescription
callPromise *

The call promise, eventually completes with the call result, or fails.

callID *

The ID of the call, used in the caching system.

Return:

Promise

The promise, complete when the given callPromise is processed.

public * blocksSaga(web3: *, getBlocksState: ReduxStateSelector): ReduxSaga source

Handles ReDApp block background processing.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

getBlocksState ReduxStateSelector

Gets blocks state (obj. incl. both blocks and latest)

Return:

ReduxSaga

Blocks saga.

public cacheCall(options: *): ReduxThunk source

Start a new call, but try to hit the cache for an existing call result first. Note: the callID is used to match with a previous call: the callID should be formatted consistently, based on address, calldata, and block-number, to hit the cache properly. The format used internally by ReDApp contract calls is: ${to}-${Web3Utils.soliditySha3(data)}-${blockNr || 'latest'}

Params:

NameTypeAttributeDescription
options *

Options for this call.

options.from *

The call sender address. Optional.

options.to *

The call destination address, i.e. the contract address.

options.data *

ABI encoded call-data. E.g. a method signature + encoded arguments for a regular contract function.

options.blockNr *

The block number to use, format corresponding to web3.js formatting: a number, or special value like 'latest'. Optional, web3.js defaults to 'latest'.

options.callID *

The ID to use within the tracking system. Optional, a new ID (uuid v4) is used when not set.

options.outputsABI *

The ABI spec of the expected outputs. Optional, if set, the raw resulting value will be decoded and stored with the other data in the store.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public * callsSaga(web3: *, getCallsState: ReduxStateSelector): ReduxSaga source

Handles ReDApp call background processing.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

getCallsState ReduxStateSelector

Gets calls state.

Return:

ReduxSaga

Calls saga.

public * contractsSaga(web3: *, defaultNetworkId: *, getContractsState: ReduxStateSelector): ReduxSaga source

import contractsSaga from 'redapp/es/contracts/contractsSaga.js'

Handles ReDApp contract background processing, e.g. loading new contracts.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

defaultNetworkId *

The default network ID to use when looking up a contract address.

getContractsState ReduxStateSelector

Gets contracts state

Return:

ReduxSaga

Contracts saga.

public createTransactionPromiEvent(web3: *, txID: *, txParams: *): PromiEvent<TransactionReceipt> source

Web3 returns a "promise combined with an event emitter": we map this to redux events.

Params:

NameTypeAttributeDescription
web3 *

The web3 instance to use when sending the actual TX.

txID *

The ID of the transaction, used in the tracking system.

txParams *

The transaction parameters.

txParams.from *

Senders address, optional. (default wallet otherwise)

txParams.to *

Destination address, or undefined for contract creation.

txParams.value *

TX value in wei.

txParams.gas *

TX gas. Optional, can be determined later.

txParams.gasPrice *

TX gas price. Optional, defaults to web3.eth.gasPrice.

txParams.data *

Optional. TX data, i.e. abi encoded contract call, or contract code itself for contract creation.

txParams.nonce *

Optional, can be used to re-send a transaction (with higher gas).

Return:

PromiEvent<TransactionReceipt>

The redux saga channel.

public fetchAllAcounts(): ReduxThunk source

import {fetchAllAcounts} from 'redapp/es/tracking/accounts/actions/index.js'

Update the list of wallet accounts.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public forceCall(options: *): ReduxThunk source

Start a new call, ignoring previous call data, forcing an overwrite when getting the result.

Params:

NameTypeAttributeDescription
options *

Options for this call.

options.from *

The call sender address. Optional.

options.to *

The call destionation address, i.e. the contract address.

options.data *

ABI encoded call-data. E.g. a method signature + encoded arguments for a regular contract function.

options.blockNr *

The block number to use, format corresponding to web3.js formatting: a number, or special value like 'latest'. Optional, web3.js defaults to 'latest'.

options.callID *

The ID to use within the tracking system. Optional, a new ID (uuid v4) is used when not set.

options.outputsABI *

The ABI spec of the expected outputs. Optional, if set, the raw resulting value will be decoded and stored with the other data in the store.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public forgetCall(callID: *): ReduxThunk source

Remove a call from the tracking system. Note: this does not cancel the call if it was already sent to the web3 instance.

Params:

NameTypeAttributeDescription
callID *

The ID of the call to remove.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public forgetContract(contractName: *): ReduxThunk source

import {forgetContract} from 'redapp/es/contracts/actions/index.js'

Removes the contract from the local redux store. Note: this does not affect the real contract in any way.

Params:

NameTypeAttributeDescription
contractName *

The name of the contract (key in the state tree)

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public forgetLocalAccount(address: *): ReduxThunk source

import {forgetLocalAccount} from 'redapp/es/tracking/accounts/actions/index.js'

Forget local account.

Params:

NameTypeAttributeDescription
address *

The address of the account to forget.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public forgetTX(txID: *): ReduxThunk source

Remove a transaction from the tracking system. Note: this does not cancel the transaction if it was already sent to the web3 instance (it may still be broadcasted, if wasn't already)

Params:

NameTypeAttributeDescription
txID *

The ID of the transaction to remove.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public getAllAccounts(): ReduxThunk source

import {getAllAccounts} from 'redapp/es/tracking/accounts/actions/index.js'

Get data (like the balance) for each account in the tracker

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public getBalance(address: *): ReduxThunk source

To start updating the balance of an account

Params:

NameTypeAttributeDescription
address *

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public getBlock(blockHandle: *): ReduxThunk source

Get a specific block. (Warning; block will not be inserted into the state when it's out of scope of the tracking blockDepth. However, the retrieval and events will still be executed.)

Params:

NameTypeAttributeDescription
blockHandle *

The hash, number, of special name ("genesis", "latest", "pending") of the block to get.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public getLatestBlock(): ReduxThunk source

import {getLatestBlock} from 'redapp/es/tracking/blocks/actions/index.js'

Force retrieval of the latest block.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public getSingleAccount(address: *): ReduxThunk source

import {getSingleAccount} from 'redapp/es/tracking/accounts/actions/index.js'

Get data for an individual account.

Params:

NameTypeAttributeDescription
address *

The address to get the data for.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public * getSpecificBlock(web3: *, action: *): ReduxSaga source

Params:

NameTypeAttributeDescription
web3 *

Web3 handle.

action *

The action to handle.

action.blockHandle *

The hash, number, of special name ("genesis", "latest", "pending") of the block to get.

Return:

ReduxSaga

Saga generator

public initWeb3(fallback: *): * source

import initWeb3 from 'redapp/es/initWeb3.js'

Initializes web3 in a fairly standard way. Utility function, for the "lazy" dev.

Params:

NameTypeAttributeDescription
fallback *

An object specifying what to use when no provider was found.

Return:

*

Web3 A new web3 instance, or throws an error if failing to instantiate.

public initiateCall(web3: *, callID: *, blockNr: *, callParams: *): Promise source

Initiate a web3 call, it starts waiting for a promise that is mapped to our redux call system.

Params:

NameTypeAttributeDescription
web3 *

The web3 instance to use when sending the actual TX.

callID *

The ID of the transaction, used in the tracking system.

blockNr *

The block number to use in the computation of the call, as call context. (Optional, web3 defaults to the "latest" block).

callParams *

The call parameters

callParams.from *

Senders address, optional. (default wallet otherwise)

callParams.to *

Destination address, or undefined for contract creation.

callParams.data *

Optional. TX data, i.e. abi encoded contract call, or contract code itself for contract creation. (99% of calls should have it though.)

Return:

Promise

The redux saga channel.

public mappedreducer(mapping: *, initialState: *): Function source

import mappedreducer from 'redapp/es/util/mapped-reducer.js'

Creates a simple reducer, based on a mapping and an initial state. Similar to redux-actions, but much less bloated.

Params:

NameTypeAttributeDescription
mapping *

An object with a mapping function for each action type, actions without key in this mapping are ignored.

initialState *

The state to use when there is none available.

Return:

Function

The reducer.

public openTxChannel(promiEvent: *, txID: *): Channel<any> source

Open a TX channel: this channel maps web3 events to our redux tracking system.

Params:

NameTypeAttributeDescription
promiEvent *

The event emitter to read transaction status updates from.

txID *

The ID of the transaction, used in the tracking system.

Return:

Channel<any>

The redux saga channel.

public poller(startAT: *, stopAT: *, workerInner: *, errorHandler: *, workerArgs: *): pollWatcher source

import poller from 'redapp/es/util/poller.js'

Simple redux saga utility for polling. Returns a watcher saga that listens for an action of type startAT, and then starts polling. Polling is then stopped when the watcher notices an action of type stopAT. Polling can be resumed with an action of type startAT again.

Params:

NameTypeAttributeDescription
startAT *

The action type to listen for to start polling. This action should have a property 'interval', specifying the number of milliseconds to wait before executing the next poll iteration.

stopAT *

The action type to listen for to stop polling.

workerInner *

A saga that is called each poll iteration.

errorHandler *

A saga that is called on an error during a polling iteration. Optional, error is propagated otherwise.

workerArgs *

The remaining function arguments are forwarded to workerInner.

Return:

pollWatcher

The watcher saga, controlling the inner worker saga.

public * saga(web3: *, defaultNetworkId: *, getRootState: *): ReduxSaga source

import saga from 'redapp/es/saga.js'

Forks to tracking and contracts saga.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

defaultNetworkId *

The network ID to resort to when no specific network ID is specified in an action.

getRootState *

A state selector (E.g. (state) => state.redapp) that points to the root of the ReDApp state. This pattern repeats for each saga, enabling you to compose custom state structures.

Return:

ReduxSaga

The ReDApp root saga.

public sendTX(options: *): ReduxThunk source

Send a transaction, which will be tracked in the ReDApp tracking system.

Params:

NameTypeAttributeDescription
options *

Options

options.from *

The transaction sender address.

options.to *

The transaction destination address. Optional, e.g. not used for contract deployments.

options.value *

The value, ETH. Optional, defaults to 0.

options.gas *

Gas, in wei. Optional, can be calculated on the fly by web3 provider.

options.gasPrice *

Gas price. Optional, can be set by web3 provider later on.

options.data *

ABI encoded data to send with the transaction. Used for contract deploying and contract interaction. Optional, e.g. a normal ETH transfer.

options.nonce *

The transaction nonce. Optional, can be determined automatically by the web3 provider.

options.txID *

The ID to use within the tracking system. Optional, a new ID (uuid v4) is used when not set.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public startAccountPolling(interval: *): ReduxThunk source

import {startAccountPolling} from 'redapp/es/tracking/accounts/actions/index.js'

Start polling for accounts.

Params:

NameTypeAttributeDescription
interval *

The polling interval in milliseconds.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public startBlockListening(): ReduxThunk source

import {startBlockListening} from 'redapp/es/tracking/blocks/actions/index.js'

Start listening for block headers, a new header will trigger the retrieval of the latest block.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public startBlockPolling(interval: *): ReduxThunk source

import {startBlockPolling} from 'redapp/es/tracking/blocks/actions/index.js'

Start polling blocks.

Params:

NameTypeAttributeDescription
interval *

The polling interval in milliseconds.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public stopAccountPolling(): ReduxThunk source

import {stopAccountPolling} from 'redapp/es/tracking/accounts/actions/index.js'

Stop polling for accounts.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public stopBlockListening(): ReduxThunk source

import {stopBlockListening} from 'redapp/es/tracking/blocks/actions/index.js'

Stop listening for block headers.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public stopBlockPolling(): ReduxThunk source

import {stopBlockPolling} from 'redapp/es/tracking/blocks/actions/index.js'

Stop polling blocks. Polling can be resumed later with startPolling again.

Return:

ReduxThunk

Redux thunk, dispatch to run action.

public subber(startAT: *, stopAT: *, dataAT: *, changedAT: *, errorAT: *, openEventSub: *): subscriptionWatcher source

import subber from 'redapp/es/util/subber.js'

Maps an event-emitter (like web3.js uses) to a redux-saga event-channel, with support for being started/stopped/resumed.

Params:

NameTypeAttributeDescription
startAT *

The action type that starts/resumes it.

stopAT *

The action type that stops it.

dataAT *

The action type that will be emitted when a "data" event is received from the subscription. Payload property = 'data'

changedAT *

The action type that will be emitted when a "changed" event is received from the subscription. Payload property = 'changed'

errorAT *

The action type that will be emitted when a "error" event is received from the subscription. Payload property = 'err'

openEventSub *

A function that returns a new EventEmitter ready to subscribe to.

Return:

subscriptionWatcher

The watcher, a redux-saga, can be shut down to stop the service completely. Controls the inner event-channel (like the worker in the poller utility).

public * trackingSaga(web3: *, getTrackingState: ReduxStateSelector): ReduxSaga source

import trackingSaga from 'redapp/es/tracking/trackingSaga.js'

Forks to tracking and contracts saga.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

getTrackingState ReduxStateSelector

Gets tracking state.

Return:

ReduxSaga

Tracking saga.

public * transactionsSaga(web3: *, getTransactionsState: ReduxStateSelector): ReduxSaga source

Handles ReDApp transaction background processing.

Params:

NameTypeAttributeDescription
web3 *

The web3js 1.0 instance to use.

getTransactionsState ReduxStateSelector

Gets transactions state.

Return:

ReduxSaga

Transactions saga.