1.0.5 • Published 5 months ago

woo-web3 v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

woo-web3

Web3Manager Class

The Web3Manager class provides a convenient interface for interacting with an Ethereum blockchain. Here's a guide on how to use its methods:

Class Instantiation

To use the `Web3Manager class, you need to instantiate it by providing the Ethereum node provider URL and the private key of the Ethereum account you want to manage.

const Web3Manager = require('woo-web3')

// Replace 'your-ethereum-node-url' and 'your-private-key' with actual values
const web3Manager = new Web3Manager('your-ethereum-node-url', 'your-private-key');

Methods

getTransaction(txHash: string): Promise<TransactionResponse | null>

This method retrieves details of a specific Ethereum transaction using its hash.

Usage:

const transactionDetails = await web3Manager.getTransaction('transaction-hash');
console.log(transactionDetails);

getBlock(blockHashOrBlockTag: ethers.BlockTag): Promise<ethers.Block | null>

Retrieve details of a specific Ethereum block using its hash or tag.

Usage:

const blockDetails = await web3Manager.getBlock('block-hash-or-tag');
console.log(blockDetails);

getBalance(address: string): Promise<string>

Get the balance of an Ethereum account in ether.

Usage:

const balance = await web3Manager.getBalance('ethereum-address');
console.log(balance);

transferBalance(amount: string, destinationAddress: string): Promise<TransactionResponse>

Transfer a specified amount of Ether to a destination address.

Usage:

const transactionResponse = await web3Manager.transferBalance('0.1', 'recipient-address');
console.log(transactionResponse);

isLegacyChain(): Promise<boolean>

Check if the Ethereum chain is using the legacy gas fee system.

Usage:

const isLegacy = await web3Manager.isLegacyChain();
console.log(isLegacy);

execute(options: ExecuteFunctionOptions): Promise<unknown>

Execute a function on a smart contract.

Params:

ExecuteFunctionOptions {
  contractAddress: string
  contractAbi: Array<any>
  method: string
  value?: string
  params?: Array<any>
  overrides?: {
    gasLimit?: BigNumberish
    gasPrice?: BigNumberish
    maxPriorityFeePerGas?: BigNumberish
    maxFeePerGas?: BigNumberish
  }
}

Usage:

const executeResult = await web3Manager.execute({
  contractAddress: 'contract-address',
  contractAbi: [...],                 // ABI of the contract
  method: 'contract-function-name',
  value: '0',                         // Optional
  params: [param1, param2],           // Optional
  overrides: { gasLimit: 50000 }      // Optional
});
console.log(executeResult);

Complete example:

async function executeContractFunction() {
  try {
    // Instantiate Web3Manager
    const web3Manager = new Web3Manager('your-ethereum-node-url', 'your-private-key');

    // Execution options
    const executeOptions: ExecuteFunctionOptions = {
      contractAddress: '0x',
      contractAbi: [...],
      method: 'balanceOf',
      params: [...],
    };


    // Execute the contract function
    const result = await web3Manager.execute(executeOptions);

    // Print the result of the execution
    console.log('Contract executed successfully. Result:', result);
  } catch (error) {
    // Handle errors in contract execution
    console.error('Error executing the contract:', error);
  }
}

// Call the function
executeContractFunction();

Replace placeholder values like 'your-ethereum-node-url', 'your-private-key', 'transaction-hash', 'block-hash-or-tag', 'ethereum-address', 'recipient-address', 'contract-address', and other relevant values with actual data.

1.0.2

5 months ago

1.0.1

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.0

5 months ago