getModule

The getModule method is the most basic way to get the interact-able contract instance for a given module.

Parameters: an object with the following properties

{
    // the name of the module smart contract
    name: ModuleName
    // the address of the deployed module
    address: `0x${string}`
    // the public client or provider to make RPC calls
    publicClient: PublicClient
    // the wallet client to sign and submit transactions
    walletClient: WalletClient
    extras?: {
      // the wallet address of the user
      walletAddress?: `0x${string}`
      // the number of decimals of the funding token of the funding manager
      decimals?: number
      // the default token to use
      defaultToken?: `0x${string}`
      // the number of decimals of the issuance token
      issuanceTokenDecimals?: number
      // the issuance token to use
      issuanceToken?: `0x${string}`
    }
}

Returns: a Module object with the following properties

{
    // the name of the module smart contract
    name: ModuleName
    // the address of the deployed module
    address: `0x${string}`
    // the type of the module (e.g. authorizer)
    moduleType: ModuleType
    // short description of the module taken from the contract NatSpec documentation
    description: string
    write: {
        [functionName: string]: {
            // name of the function
            name: string
            // description of what the function does taken from NatSpec
            description: string
            inputs: ExtendedAbiParameter[]
            outputs: ExtendedAbiParameter[]
            // an asynchronous function that whose parameters are of type Primitive<`inputs`> and return values are of type Primitive<`outputs`>
            run: (args: GetMethodArgs, options?: MethodOptions) => Promise<GetMethodResponse>
        }
    }
    estimateGas: // same as write ...
    simulate: // same as write ...
    read: // same as write ...
}

Example:

import { getModule } from '@inverter-network/sdk'

const { 
    name,
    address,
    moduleType,
    description,
    estimateGas,
    read,
    simulate,
    write
} = getModule({
        name: 'LM_PC_Bounties_v1',
        address: '0xa23D85d8FE256a8a1eE92a6d5Ec156a8a21DCdaE',
        publicClient,
        walletClient,
        extras: {
            decimals: 18,
        },
    })
    
const addBountyArgs = [
     '100',
     '1000',
     ['this is an inverter project'],
] as const
    
// estimateGas function estimates the gas and returns raw and formatted
const { value, formatted } = await estimateGas.addBounty.run(addBountyArgs)
    
// simulate function simulates the function and returns the outputs
const outputs = await simulate.addBounty.run(addBountyArgs)

// write function changes the state of the smart contract
const txHash = await write.addBounty.run(addBountyArgs, {
    confirmations: 1,
    onHash: (hash) => {console.log(hash)},
    onConfirmation: (receipt) => {console.log(receipt)},
})

// read function gets some value(s) from the smart contract
const bountyIds = await read.listBountyIds.run()

Last updated