How to use the @celo/contractkit.newKitFromWeb3 function in @celo/contractkit

To help you get started, we’ve selected a few @celo/contractkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celo-org / celo-monorepo / packages / celotool / src / e2e-tests / governance_tests.ts View on Github external
await initAndStartGeth(context.hooks.gethBinaryPath, groupInstance)
      allValidators = await getValidatorGroupMembers()
      assert.equal(allValidators.length, 5)
      epoch = new BigNumber(await validators.methods.getEpochSize().call()).toNumber()
      assert.equal(epoch, 10)

      // Give the nodes time to sync, and time for an epoch transition so we can activate our vote.
      let blockNumber: number
      do {
        blockNumber = await web3.eth.getBlockNumber()
        await sleep(0.1)
      } while (blockNumber % epoch !== 1)

      await activate(allValidators[0])
      const groupWeb3 = new Web3('ws://localhost:8567')
      const groupKit = newKitFromWeb3(groupWeb3)
      validators = await groupKit._web3Contracts.getValidators()
      const membersToSwap = [allValidators[0], allValidators[1]]
      let includedMemberIndex = 1
      await removeMember(groupWeb3, groupAddress, membersToSwap[0])

      const changeValidatorSet = async (header: any) => {
        blockNumbers.push(header.number)
        // At the start of epoch N, swap members so the validator set is different for epoch N + 1.
        if (header.number % epoch === 1) {
          const memberToRemove = membersToSwap[includedMemberIndex]
          const memberToAdd = membersToSwap[(includedMemberIndex + 1) % 2]
          await removeMember(groupWeb3, groupAddress, memberToRemove)
          await addMember(groupWeb3, groupAddress, memberToAdd)
          includedMemberIndex = (includedMemberIndex + 1) % 2
          const newMembers = await getValidatorGroupMembers()
          assert.include(newMembers, memberToAdd)
github celo-org / celo-monorepo / packages / notification-service / src / util / utils.ts View on Github external
export async function getContractKit(): Promise {
  if (contractKit && (await contractKit.isListening())) {
    // Already connected
    return contractKit
  } else {
    const httpProvider = new Web3.providers.HttpProvider(WEB3_PROVIDER_URL)
    const web3 = new Web3(httpProvider)
    contractKit = newKitFromWeb3(web3)
    return contractKit
  }
}
github celo-org / celo-monorepo / packages / celotool / src / helpers / account_register.ts View on Github external
;(async () => {
  const kit = newKitFromWeb3(web3)
  const account = await importAndUnlockAccount(web3, keystorePath)
  const from = account.address
  const accountContract = await kit.contracts.getAccounts()
  const isAccount = await accountContract.isAccount(from)
  if (!isAccount) {
    // register
    await displaySendTx('register', accountContract.createAccount(), { from: from })
    // set name
    const accountName: string = process.env.NAME || `account-${account.address}`
    await delay(1000)
    await displaySendTx('setName', accountContract.setName(accountName), { from: from })
    // set encryption key
    const publicKey = add0x(generatePublicKeyFromPrivateKey(account.privateKey.slice(2)))
    const registerDataEncryptionKeyTx = accountContract.setAccountDataEncryptionKey(
      publicKey as any
    )
github celo-org / celo-monorepo / packages / celotool / src / e2e-tests / slashing_tests.ts View on Github external
const restart = async () => {
    await context.hooks.restart()
    web3 = new Web3('http://localhost:8545')
    kit = newKitFromWeb3(web3)
    console.log(await web3.eth.getAccounts())
    //goldToken = await kit._web3Contracts.getGoldToken()
    //stableToken = await kit._web3Contracts.getStableToken()
    //sortedOracles = await kit._web3Contracts.getSortedOracles()
    //validators = await kit._web3Contracts.getValidators()
    //registry = await kit._web3Contracts.getRegistry()
    //reserve = await kit._web3Contracts.getReserve()
    //election = await kit._web3Contracts.getElection()
    //epochRewards = await kit._web3Contracts.getEpochRewards()
    //accounts = await kit._web3Contracts.getAccounts()
  }
github celo-org / celo-monorepo / packages / celotool / src / cmds / transactions / list.ts View on Github external
export const handler = async (argv: ListArgv) => {
  await switchToClusterFromEnv(false)

  await downloadArtifacts(argv.celoEnv)
  await copyContractArtifacts(
    argv.celoEnv,
    '../transaction-metrics-exporter/src/contracts',
    CONTRACTS_TO_COPY
  )

  const web3 = await getWeb3Client(argv.celoEnv)
  const blockscoutURL = getBlockscoutUrl(argv.celoEnv)
  const kit = await newKitFromWeb3(web3)
  const blockExplorer = await newBlockExplorer(kit)
  const logExplorer = await newLogExplorer(kit)
  const resp = await fetch(
    `${blockscoutURL}/api?module=account&action=txlist&address=${argv.address}&sort=desc`
  )
  const jsonResp = await resp.json()

  if (jsonResp.result === undefined) {
    return
  }

  for (const blockscoutTx of jsonResp.result) {
    await fetchTx(web3, blockExplorer, logExplorer, blockscoutTx)
  }
  process.exit(0)
}
github celo-org / celo-monorepo / packages / leaderboard / src / board.ts View on Github external
async function readAssoc(lst: string[]) {
  const web3 = new Web3(LEADERBOARD_WEB3)
  const kit: ContractKit = newKitFromWeb3(web3)
  const accounts: AccountsWrapper = await kit.contracts.getAccounts()
  lst.forEach(async (a) => {
    try {
      const url = await accounts.getMetadataURL(a)
      console.log(a, 'has url', url)
      let metadata: IdentityMetadataWrapper
      if (url == '') metadata = IdentityMetadataWrapper.fromEmpty(a)
      else metadata = await IdentityMetadataWrapper.fetchFromURL(url)
      processClaims(kit, a, metadata)
    } catch (err) {
      console.error('Bad address', a, err.toString())
    }
  })
}
github celo-org / celo-monorepo / packages / celotool / src / helpers / utils.ts View on Github external
export async function lockGoldIfNeeded(web3: Web3, from: string) {
  const minLockedGold = new BigNumber(20000000000000000000000)
  const kit = newKitFromWeb3(web3)
  const lockedGoldContract = await kit.contracts.getLockedGold()
  const nonvotingGold = await lockedGoldContract.getAccountNonvotingLockedGold(from)
  if (nonvotingGold.lt(minLockedGold)) {
    const txLock = lockedGoldContract.lock()
    await displaySendTx('lock', txLock, {
      from: from,
      value: minLockedGold.toString(),
    })
  }
}