Skip to main content

API

Namespaces

Enumerations

Classes

Interfaces

Type Aliases

EventSource

Ƭ EventSource: EventSources[keyof EventSources]

An EventSource is essentially an ethers contract, that we can keep track of


MetadataEvent

Ƭ MetadataEvent<K>: typeof IPFS_METADATA_EVENTS[K]

Type parameters

NameType
Kextends MetadataType

MetadataValue

Ƭ MetadataValue<K>: ReturnType<typeof IPFS_METADATA_PARSERS[K]>

Type parameters

NameType
Kextends MetadataType

Variables

DecisionMotionCode

Const DecisionMotionCode: "0x12345678"

Identifies a motion as a decision

Usually there's no need to use this directly. Use VotingReputation.createDecision instead.

Functions

addressesAreEqual

addressesAreEqual(a, b): boolean

Check if two addresses are equal

Parameters

NameType
astring
bstring

Returns

boolean


createSubgraphClient

createSubgraphClient(options?): Client

Creates a Colony Subgraph client

The Colony Subgraph client is nothing else than a ready-to-use urql client connected to the Colony Subgraph with subscriptions enabled. Please refer to the following references if you'd like to know more about The Graph or GraphQL in general.

The Colony Subgraph's schema and resolvers are kept up-to-date by the Colony team and can be explored here: Colony Subgraph. There you can make test queries to the Colony Subgraph and explore it all the way down the rabbit hole :)

Example

Retrieve the 10 most recent "DomainAdded" events across all Colonies

import { createSubgraphClient, gql } from '@colony/sdk/graph';

const colonySubgraph = createSubgraphClient();

const QUERY = gql`
query DomainAddedEvents {
events(
first: 10
orderBy: timestamp
orderDirection: desc
where: { name_contains: "DomainAdded" }
) {
id
address
associatedColony {
colonyAddress: id
}
name
args
timestamp
}
}
`;

colonySubgraph
.query(QUERY)
.toPromise()
.then((result) => {
console.info(result.data.events[0]);
});

Parameters

NameTypeDescription
options?SubgraphClientOptionsDefine configuration options to instantiate the client with

Returns

Client

A ready-to-use urql GraphQL client instance


extractCustomEvent

extractCustomEvent<T>(eventName, receipt, iface): undefined | T

Manually extract an event using the interface (e.g. if emitting contract is a different one than the calling contract)

Type parameters

Name
T

Parameters

NameType
eventNamestring
receiptContractReceipt | ParsedLogTransactionReceipt
ifaceInterface

Returns

undefined | T


extractEvent

extractEvent<T>(eventName, receipt): undefined | T

Extract event args from a contract receipt

Type parameters

Name
T

Parameters

NameType
eventNamestring
receiptContractReceipt | ParsedLogTransactionReceipt

Returns

undefined | T


getLogs

getLogs(filter, provider): Promise<Log[]>

Version of getLogs that also supports filtering for multiple addresses

Parameters

NameType
filterEthers6Filter | Ethers6FilterByBlockHash | Promise<Ethers6Filter | Ethers6FilterByBlockHash>
providerJsonRpcProvider

Returns

Promise<Log[]>


gql

gql<Data, Variables>(strings, ...interpolations): TypedDocumentNode<Data, Variables>

Type parameters

NameType
Dataany
Variablesobject

Parameters

NameType
stringsTemplateStringsArray
...interpolations(string | DocumentNode | TypedDocumentNode<{ [key: string]: any; }, { [key: string]: any; }>)[]

Returns

TypedDocumentNode<Data, Variables>

gql<Data, Variables>(string): TypedDocumentNode<Data, Variables>

Type parameters

NameType
Dataany
Variablesobject

Parameters

NameType
stringstring

Returns

TypedDocumentNode<Data, Variables>


nonNullable

nonNullable<T>(value): value is NonNullable<T>

Use this to filter empty undefinied values from arrays in a type-safe way

Type parameters

Name
T

Parameters

NameType
valueT

Returns

value is NonNullable<T>


parseRoles

parseRoles(roles): ColonyRole[]

Parses a binary role integer into a ColonyRole array

When getting multiple roles from contract methods or events they are usually formatted as a binary number. Here the least significant bit is the role with the index 0 (Recovery).

E.g. 5 = 0b00101 equals Recovery and Arbitration

This function parses these binary integers into a ColonyRole array.

Parameters

NameTypeDescription
rolesstringA hex string (e.g. 0x3 = 0b11 equals Recovery and Root roles)

Returns

ColonyRole[]


toEth

toEth(num): string

Convert any number to ETH (remove 18 zeros)

Example

import { toEth } from '@colony/sdk';

const oneEther = BigNumber.from("1000000000000000000");
console.log(toEth(oneEther)); // 1.0

Parameters

NameType
numBigNumberish

Returns

string


toWei

toWei(num): BigNumber

Convert any number to wei (add 18 zeros)

Example

import { toWei } from '@colony/sdk';

const oneEther = '1.0';
console.log(toWei(oneEther)); // { BigNumber: "1000000000000000000" }

Parameters

NameType
numstring

Returns

BigNumber


w

w(str): BigNumber

Short-hand method to convert a number to wei using JS tagged template strings

See also here: http://tc39wiki.calculist.org/es6/template-strings/

Remarks

This is only useful in contexts where the number is hard-coded (e.g. examples)

Example

import { w } from '@colony/sdk';

console.log(w`1.0`); // { BigNumber: "1000000000000000000" }

Parameters

NameType
strTemplateStringsArray

Returns

BigNumber