Clients
Clients are aggregations of all the interactions possible with the colonyNetwork smart contracts that can be used to easily integrate Colony into your JavaScript application or service.
Network Client
Use getNetworkClient
to get an instance of ColonyNetworkClient:
// Import the getNetworkClient method
const { getNetworkClient } = require('@colony/colony-js-client');
// Get the network client using the local network
const networkClient = getNetworkClient('local', wallet);
// Get the network client using the goerli network
const networkClient = getNetworkClient('goerli', wallet);
// Get the network client using the main network
const networkClient = getNetworkClient('mainnet', wallet);
If you would like to use a specific Infura Project ID, you can pass it in as a third parameter.
// Get the network client using the main network using a Infura Project ID
const networkClient = getNetworkClient('mainnet', wallet, infuraProjectId);
If you are using this method with the local
option, you will need to have trufflepig installed and running. We recommend using purser to get a wallet instance but you can also use ethers.
Alternatively, you can create an instance of ColonyNetworkClient by instantiating its class using an adapter and then initializing it using the init
method:
const networkClient = new ColonyNetworkClient({ adapter });
await networkClient.init();
See Adapters for more information about adapters.
Colony Client
Use getColonyClient
to get an instance of ColonyClient:
// Import the getColonyClient method
const { getColonyClient } = require('@colony/colony-js-client');
// Get the colony client using the local network
const colonyClient = getColonyClient(colonyAddress, 'local', wallet);
// Get the colony client using the goerli network
const colonyClient = getColonyClient(colonyAddress, 'goerli', wallet);
// Get the colony client using the main network
const colonyClient = getColonyClient(colonyAddress, 'mainnet', wallet);
If you would like to use a specific Infura Project ID, you can pass it in as a fourth parameter.
// Get the network client using the main network using a specific Infura Project ID
const networkClient = getColonyClient(
colonyAddress,
'mainnet',
wallet,
infuraProjectId,
);
If you are using this method with the local
option, you will need to have trufflepig installed and running. We recommend using purser to get a wallet instance but you can also use ethers.
Alternatively, you can get an instance of ColonyClient from the ColonyNetworkClient:
const colonyClient = await networkClient.getColonyClient(colonyId);
And like ColonyNetworkClient, you can create an instance of ColonyClient by instantiating the ColonyClient class using an adapter and query and then initializing it using the init
method:
const colonyClient = new ColonyClient({
adapter,
query: {
contractAddress: '0x0000000000000000000000000000000000000000',
},
});
await colonyClient.init();
See Adapters for more information about adapters.
Colony Client (Meta Colony)
Ask the NetworkClient
for an instance of ColonyClient for the Meta Colony:
const metaColonyClient = await networkClient.getMetaColonyClient();
Alternatively, you can create an instance of ColonyClient by instantiating the ColonyClient class using an adapter and query and then initializing it using the init
method:
const metaColonyClient = new ColonyClient({
adapter,
query: {
contractAddress: '0x0000000000000000000000000000000000000000',
},
});
await metaColonyClient.init();
See Adapters for more information about adapters.
Token Client
The TokenClient
is initialized for you when you ask for a new instance of ColonyClient:
const tokenClient = colonyClient.tokenClient;
Alternatively, you can create an instance of TokenClient
by instantiating the TokenClient
class using an adapter and query and then initializing it using the init
method:
const tokenClient = new TokenClient({
adapter,
query: {
contractAddress: '0x0000000000000000000000000000000000000000',
},
});
await tokenClient.init();
See Adapters for more information about adapters.
Token Locking Client
The TokenLockingClient
is initialized for you when you ask for a new instance of ColonyClient:
const tokenLockingClient = colonyClient.tokenLockingClient;
Alternatively, you can create an instance of TokenLockingClient
by instantiating the TokenLockingClient
class using an adapter and query and then initializing it using the init
method:
const tokenLockingClient = new TokenLockingClient({
adapter,
query: {
contractAddress: '0x0000000000000000000000000000000000000000',
},
});
await tokenLockingClient.init();
See Adapters for more information about adapters.
Support
Questions? Problems? Existential dilemmas? We’re here to help!
Improve this doc.
All improvements to documentation are welcome and encouraged. Submit a PR for documentation on GitHub.