New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

woo-web3

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

woo-web3

  • 1.0.5
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 23 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc