1.0.6 • Published 3 years ago

web3-call v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Table of Contents

Use the "Table of Contents" menu on the top-left corner to explore the list.

Resources

Official Resources

Get Started

npm install web3-call --save
yarn add web3-call

Example

/*
  Initialize JsonRPCProvider to connect with blockchain. 
  For example: Get account balance and logs it to console. 
*/

// 1_getBalance.ts

import {
  getProvider,
  DEFAULT_RPC,
  getContractNoSigner,
  KAP20ABI,
} from "web3-call";
import type { KAP20 } from "web3-call";

import { ethers } from "ethers";
import { account1, ADDRESS } from "./config";

const main = async () => {
  const provider = getProvider(DEFAULT_RPC.bitkubTestnet);

  const balance = await provider.getBalance(account1);
  console.log(
    `\nKUB Balance of ${account1} --> ${ethers.utils.formatEther(
      balance
    )} KUB\n`
  );
};

main();
/*
  Initialize Contract without signer just for *READ* Smartcontract 
*/
import {
  getProvider,
  DEFAULT_RPC,
  getContractNoSigner,
  KAP20ABI,
} from "web3-call";
import type { KAP20 } from "web3-call";

import { ethers } from "ethers";
import { account1, ADDRESS } from "./config";

const main = async () => {
  const provider = getProvider(DEFAULT_RPC.bitkubTestnet);

  const KAP20Contract =
    getContractNoSigner < KAP20 > (ADDRESS.KUSDC, KAP20ABI, provider);

  const KUSDBalance = await KAP20Contract.balanceOf(account1);

  console.log(
    `\nKUSD Balance of ${account1} --> ${ethers.utils.formatEther(
      KUSDBalance
    )} KUSD\n`
  );
};

main();
/*
  Initialize Contract with signer for *READ* and *Write* to Smartcontract 
  TODO: Create new activity and get logs info returned from Smartcontract. 
*/

import { getProvider, DEFAULT_RPC, getContract, FactoryABI } from "web3-call";
import type { Factory } from "web3-call";
import { ADDRESS, ownerAddress, ownerPrivateKey, RewardType } from "./config";
import { parseEther } from "ethers/lib/utils";

const main = async () => {
  const provider = getProvider(DEFAULT_RPC.bitkubTestnet);

  const FactoryContract =
    getContract <
    Factory >
    (ADDRESS.Factory, ownerPrivateKey, FactoryABI, provider);

  console.log(`\nReading from ${ADDRESS.Factory}\n`);

  const tx = await FactoryContract.createPair(
    Math.floor(Date.now() / 1000), //_startTime ( Now)
    Math.floor((Date.now() + 30 * 60000) / 1000), // _endTime (Now + 30 minutes)
    { from: ownerAddress }
  );
  const txReceipt = await tx.wait();
  console.log(txReceipt);
  const log = FactoryContract.interface.parseLog(txReceipt.logs[1]);
  const newActivityAddress = log.args[0];

  console.log(
    `\New activity address has been created: ${newActivityAddress} \n`
  );
};

main();

More example: Please contact with @ jamesnguyen.tech@gmail.com

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago