Bandada utils
General Bandada utility functions.
This package provides simple utility functions that can be used by Bandada itself or externals. |
---|
🛠 Install
npm or yarn
Install the @bandada/utils
package with npm:
npm i @bandada/utils
or yarn:
yarn add @bandada/utils
📜 Usage
# request(url: string, config?: AxiosRequestConfig): Promise<any>
Makes a request using Axios.
import { request } from "@bandada/utils"
const url = "https://api.bandada.pse.dev/groups"
const config = {
headers: {
"Content-Type": "application/json"
},
baseURL: "https://api.bandada.pse.dev"
}
const group = await request(url, config)
# shortenAddress(address: string, chars: number): string
Returns a shorter address.
import { shortenAddress } from "@bandada/utils"
const address = shortenAddress("0x1234567890123456789012345678901234567890")
# getProvider(network: Network, apiKey?: string): JsonRpcProvider
Returns the provider to communicate with the blockchain.
import { getProvider } from "@bandada/utils"
const provider = getProvider("localhost")
# getContract(contractName: ContractName, network: Network, privateKeyOrSigner?: string | Signer, apiKey?: string): Contract
Returns an Ethers contract.
import { getContract } from "@bandada/utils"
const contractName = "Semaphore"
const network = "localhost"
const contract = getContract(contractName, network)
# getSemaphoreContract(network: Network, privateKeyOrSigner?: string | Signer, apiKey?: string): SemaphoreContract
Returns a new instance of the SemaphoreContract class.
import { getSemaphoreContract } from "@bandada/utils"
const semaphore = getSemaphoreContract("localhost")
# getBandadaContract(network: Network, privateKeyOrSigner?: string | Signer, apiKey?: string): BandadaContract
Returns a new instance of the BandadaContract class.
import { getBandadaContract } from "@bandada/utils"
const bandada = getBandadaContract("localhost")
# getWallet(privateKey: string, network?: Network, apiKey?: string): JsonRpcProvider
Returns an Ethers wallet.
import { getWallet } from "@bandada/utils"
const privateKey =
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
const wallet = getWallet(privateKey)
# getContractAddresses(networkName: Network): {
Bandada: string,
Semaphore: string,
BandadaSemaphore: string
}
Returns the contract addresses for the Bandada, Semaphore and BandadaSemaphore smart contracts.
import { getContractAddresses } from "@bandada/utils"
const addresses = getContractAddresses("goerli")