Posted on Tue 13 December 2022 in tech

@collectivexyz just published @collectivexyz/governance

Install from command line:

 $ npm install @collectivexyz/governance

Install using yarn:

 $ yarn add @collectivexyz/governance


Simple example to connect to a governance contract.

import { EthWallet, Governance, GovernanceBuilder, CollectiveGovernance } from '@collectivexyz/governance';
import Web3 from 'web3';

export async function connect(): Promise<Governance> {
  try {
    const rpcUrl = 'wss://localhost:8545';
    const privateKey = 'XXXXXXXXXXXX';
    const abiPath = 'node_modules/@collectivexyz/governance/abi';
    const builderAddress = '0xd64f3Db037B263D54561a2cc9885Db370B51E354';
    const buildTransaction = '0x0f7f3e13055547b8b6ac5b28285abc960266c6297094ab451ca9de318cbf5906';    
    const maximumGas = 600000;

    const web3 = new Web3(rpcUrl);

    const wallet = new EthWallet(privateKey, web3);
    const builder = new GovernanceBuilder(abiPath, builderAddress, web3, wallet, maximumGas);
    const contractAddress = await builder.discoverContract(buildTransaction);
    const governance = new CollectiveGovernance(abiPath, contractAddress.governanceAddress, web3, wallet, maximumGas);
    const name = await governance.name();
    const version = await governance.version();

    return governance;
  } catch (error) {
    throw new Error('Run failed');

More information on GitHub