Skip to main content

Class: Colony

Properties

address

address: string


colonyNetwork

colonyNetwork: ColonyNetwork


colonyToken

colonyToken: ColonyToken

An instance of the Colony's native token

Currently only Tokens deployed via Colony are supported (no external, imported tokens) in Colony SDK. All other kinds will throw an error


ext

ext: SupportedExtensions


version

version: number


SupportedVersions

Static SupportedVersions: (8 | 9)[]

The currently supported Colony version. If a Colony is not on this version it has to be upgraded. If this is not an option, Colony SDK might throw errors at certain points. Usage of ColonyJS is advised in these cases

Methods

claimFunds

claimFunds(tokenAddress?): Promise<[{ fee?: BigNumber ; payoutRemainder?: BigNumber ; token?: string }, ContractReceipt]>

Claim outstanding Colony funds

Anyone can call this function. Claims funds for the Colony that have been sent to the Colony's contract address or minted funds of the Colony's native token. This function has to be called in order for the funds to appear in the Colony's treasury. You can provide a token address for the token to be claimed. Otherwise it will claim the outstanding funds of the Colony's native token

Parameters

NameTypeDescription
tokenAddressstringThe address of the token to claim the funds for. Default is the Colony's native token

Returns

Promise<[{ fee?: BigNumber ; payoutRemainder?: BigNumber ; token?: string }, ContractReceipt]>

A tupel of event data and contract receipt

Event data

PropertyTypeDescription
agentstringThe address that is responsible for triggering this event
tokenstringThe token address
feeBigNumberThe fee deducted for rewards
payoutRemainderBigNumberThe remaining funds moved to the top-level domain pot

createTeam

createTeam(metadataCid?): Promise<[{ agent?: string ; domainId?: BigNumber ; fundingPotId?: BigNumber ; metadata?: string }, ContractReceipt, () => Promise<{ domainColor: number ; domainName: string ; domainPurpose: string }>] | [{ agent?: string ; domainId?: BigNumber ; fundingPotId?: BigNumber ; metadata?: string }, ContractReceipt]>

Create a team within a Colony

Remarks

Currently you can only add domains within the Root domain. This restriction will be lifted soon

Parameters

NameTypeDescription
metadataCid?stringAn IPFS CID for a JSON file containing the metadata described below. For now, we would like to keep it agnostic to any IPFS upload mechanism, so you have to upload the file manually and provide your own hash (by using, for example, Pinata)

Returns

Promise<[{ agent?: string ; domainId?: BigNumber ; fundingPotId?: BigNumber ; metadata?: string }, ContractReceipt, () => Promise<{ domainColor: number ; domainName: string ; domainPurpose: string }>] | [{ agent?: string ; domainId?: BigNumber ; fundingPotId?: BigNumber ; metadata?: string }, ContractReceipt]>

A tupel: [eventData, ContractReceipt, getMetaData]

Event data

PropertyTypeDescription
agentstringThe address that is responsible for triggering this event
domainIdBigNumberInteger domain id of the created team
fundingPotIdBigNumberInteger id of the corresponding funding pot
metadatastringIPFS CID of metadata attached to this transaction

Metadata (can be obtained by calling and awaiting the getMetadata function)

PropertyTypeDescription
domainNamestringThe human readable name assigned to this team
domainColorstringThe color assigned to this team
domainPurposestringThe purpose for this team (a broad description)

getBalance

getBalance(tokenAddress?, teamId?): Promise<BigNumber>

Get a token balance for a specific token and team. Defaults to the Colony's native token and the Root team.

Remarks

The function will automatically figure out the corresponding pot for the given domain, as this is what's usually expected.

Example

Get the xDAI balance of the team number 2

import { constants } from 'ethers';
import { toEth } from '@colony/sdk';
// The `AddressZero` means ETH on mainnet and xDAI on Gnosis chain
const balance = await colony.getBalance(constants.AddressZero, 2);
// This will format the balance as a string in eth and not wei (i.e. 1.0 vs. 1000000000000000000)
console.info(toEth(balance));

Parameters

NameTypeDescription
tokenAddress?stringThe address of the token to get the balance for. Default is the Colony's native token
teamId?BigNumberishThe teamId (domainId) of the team to get the balance for. Default is the Root team

Returns

Promise<BigNumber>

A token balance in wei


getReputation

getReputation(userAddress, teamId?): Promise<BigNumber>

Get the reputation for a user address within a team in the Colony

Parameters

NameTypeDefault valueDescription
userAddressstringundefinedThe address of the account to check the reputation for
teamIdIdId.RootDomainThe teamId (domainId) of the team to get the reputation for. Default is the Root team

Returns

Promise<BigNumber>

A number quantifying the user addresses' reputation


getReputationAcrossTeams

getReputationAcrossTeams(userAddress): Promise<{ domainId: number ; reputationAmount?: BigNumberish ; skillId: number }[]>

Get the reputation for a user address across all teams in the Colony

Parameters

NameTypeDescription
userAddressstringThe address of the account to check the reputation for

Returns

Promise<{ domainId: number ; reputationAmount?: BigNumberish ; skillId: number }[]>

An array of objects containing the following

PropertyDescription
domainIdThe domainId of the domain the user has reputation in
skillIdThe corresponding skillId
reputationAmountThe reputation amount in that domain

getTeam

getTeam(teamId): Promise<DomainStructOutput>

Gets the team for teamId

Remarks

Will throw if teamId does not exist

Parameters

NameTypeDescription
teamIdBigNumberishThe teamId to get the team information for FIXME: get the type somehow

Returns

Promise<DomainStructOutput>

A Team object


makeArbitraryTransaction

makeArbitraryTransaction(target, action): Promise<[{}, ContractReceipt]>

Execute an arbitrary transaction in the name of the Colony

This method can execute a transaction on any Ethereum Smart Contract with the Colony address as the sender. The action needs to be encoded function data (see https://docs.ethers.io/v5/api/utils/abi/interface/#Interface--encoding). We provide some common interfaces for you to make it even easier.

Example

Mint an NFT from a Colony

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

// Mint a NFT for address 0xb794f5ea0ba39494ce839613fffba74279579268
const encodedAction = ERC721.encodeFunctionData(
'mintTo',
'0xb794f5ea0ba39494ce839613fffba74279579268',
);

// Immediately executing async function
(async function() {
await colony.makeArbitraryTransaction(
// NFT contract address
'0x06012c8cf97BEaD5deAe237070F9587f8E7A266d',
// encoded transaction from above
encodedAction
);
})();

Parameters

NameTypeDescription
targetstringAddress of the contract to execute a method on
actionBytesLikeEncoded action to execute

Returns

Promise<[{}, ContractReceipt]>

A tupel of event data and contract receipt

No event data


moveFundsToTeam

moveFundsToTeam(amount, toTeam, fromTeam?, tokenAddress?): Promise<[{ agent?: string ; amount?: BigNumber ; fromPot?: BigNumber ; toPot?: BigNumber ; token?: string }, ContractReceipt]>

Move funds from one team to another

After sending funds to and claiming funds for your Colony they will land in a special team, the root team. If you want to make payments from other teams (in order to award reputation in that team) you have to move the funds there first. Use this method to do so.

Remarks

Requires the Funding permission in the root team. As soon as teams can be nested, this requires the Funding permission in a team that is a parent of both teams in which funds are moved.

Example

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

// Immediately executing async function
(async function() {
// Move 10 of the native token from team 2 to team 3
await colony.moveFundsToTeam(
w`10`,
2,
3,
);
})();

Parameters

NameTypeDescription
amountBigNumberishAmount to transfer between the teams
toTeamBigNumberishThe team to transfer the funds to
fromTeam?BigNumberishThe team to transfer the funds from. Default is the Root team
tokenAddress?stringThe address of the token to be transferred. Default is the Colony's native token

Returns

Promise<[{ agent?: string ; amount?: BigNumber ; fromPot?: BigNumber ; toPot?: BigNumber ; token?: string }, ContractReceipt]>

A tupel of event data and contract receipt

Event data

PropertyTypeDescription
agentstringThe address that is responsible for triggering this event
fromPotBigNumberThe source funding pot
toPotBigNumberThe target funding pot
amountBigNumberThe amount that was transferred
tokenstringThe token address being transferred

pay

pay(recipient, amount, teamId?, tokenAddress?): Promise<[{ agent?: string ; fundamentalId?: BigNumber ; nPayouts?: BigNumber }, ContractReceipt]>

Make a payment to a single address using a single token

Remarks

Requires the OneTxPayment extension to be installed for the Colony (this is usually the case for Colonies created via the Dapp). Note that most tokens use 18 decimals, so add a bunch of zeros or use our w or toWei functions (see example)

Example

import { Id, Tokens, w } from '@colony/sdk';

// Immediately executing async function
(async function() {
// Pay 10 XDAI (on Gnosis chain) from the root domain to the following address
await colony.pay(
'0xb77D57F4959eAfA0339424b83FcFaf9c15407461',
w`10`,
Id.RootDomain,
Tokens.Gnosis.XDAI,
);
})();

Parameters

NameTypeDescription
recipientstringWallet address of account to send the funds to (also awarded reputation when sending the native token)
amountBigNumberishAmount to pay in wei
teamId?BigNumberishThe team to use to send the funds from. Has to have funding of at least the amount you need to send. See Colony.moveFundsToTeam. Defaults to the Colony's root team
tokenAddress?stringThe address of the token to make the payment in. Default is the Colony's native token

Returns

Promise<[{ agent?: string ; fundamentalId?: BigNumber ; nPayouts?: BigNumber }, ContractReceipt]>

A tupel of event data and contract receipt

Event data

PropertyTypeDescription
agentstringThe address that is responsible for triggering this event
fundamentalIdBigNumberThe newly added payment id
nPayoutsBigNumberNumber of payouts in total