Skip to content

Instantly share code, notes, and snippets.

@proofoftom
Created March 30, 2020 22:11
Show Gist options
  • Select an option

  • Save proofoftom/442bb10509ffc0812d4d1a53d4d0ee06 to your computer and use it in GitHub Desktop.

Select an option

Save proofoftom/442bb10509ffc0812d4d1a53d4d0ee06 to your computer and use it in GitHub Desktop.
const { getNetworkClient } = require("@colony/colony-js-client");
const { open } = require("@colony/purser-software");
const { BN } = require("web3-utils");
(async () => {
// Get a wallet instance
const wallet = await open({
privateKey: process.env.PRIVATE_KEY
});
// Get a network client instance
const networkClient = await getNetworkClient("local", wallet);
// Create a token
const createTokenTransaction = await networkClient.createToken.send({
name: "Token",
symbol: "TKN",
decimals: 18
});
// Set the token address
const tokenAddress = createTokenTransaction.meta.receipt.contractAddress;
// Create a colony
const createColonyResponse = await networkClient.createColony.send({
tokenAddress
});
// Set the colony address
const colonyAddress = createColonyResponse.eventData.colonyAddress;
// Get a colony client instance
const colonyClient = await networkClient.getColonyClientByAddress(
colonyAddress
);
// Mint tokens
await colonyClient.tokenClient.mint.send({
address: colonyAddress,
amount: new BN("1000000000000000000")
});
// Unlock native token
await colonyClient.tokenClient.unlock.send();
// Claim colony funds
await colonyClient.claimColonyFunds.send({
token: tokenAddress
});
// Add a payment
const addPaymentResponse = await colonyClient.addPayment.send({
recipient: wallet.address,
token: tokenAddress,
amount: new BN("1000000000000000000"),
domainId: 1
});
// Set payment id and pot id
const { paymentId, potId } = addPaymentResponse.eventData;
// Move funds between funding pots
await colonyClient.moveFundsBetweenPots.send({
fromPot: 1,
toPot: potId,
amount: new BN("1000000000000000000"),
token: tokenAddress
});
// Finalize a payment
await colonyClient.finalizePayment.send({ paymentId });
// Claim a payment
await colonyClient.claimPayment.send({
paymentId,
token: tokenAddress
});
})()
.then(() => process.exit())
.catch(error => console.error(error)); //eslint-disable-line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment