Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "eth"

Index

Functions

Functions

getBalance

  • getBalance(address: string, provider: Provider | string): Promise<string>
  • Fetches the current Ether balance of a provided Ethereum address.

    example
    (async function () {
    
      balance = await Venus.eth.getBalance(myAddress, provider);
      console.log('My BNB Balance', +balance);
    
    })().catch(console.error);

    Parameters

    • address: string

      The Ethereum address in which to get the BNB balance.

    • provider: Provider | string

    Returns Promise<string>

    Returns a BigNumber hexadecimal value of the BNB balance of the address.

read

  • read(address: string, method: string, parameters?: any[], options?: CallOptions): Promise<any>
  • This is a generic method for invoking JSON RPC's eth_call with Ethers.js. Use this method to execute a smart contract's constant or non-constant member without using gas. This is a read-only method intended to read a value or test a transaction for valid parameters. It does not create a transaction on the block chain.

    example
    const vBnbAddress = Venus.util.getAddress(Venus.vBNB);
    
    (async function() {
    
      const srpb = await Venus.eth.read(
        vBnbAddress,
        'function supplyRatePerBlock() returns (uint256)',
        // [], // [optional] parameters
        // {}  // [optional] call options, provider, network, plus Ethers.js "overrides"
      );
    
      console.log('vBNB market supply rate per block:', srpb.toString());
    
    })().catch(console.error);

    Parameters

    • address: string

      The Ethereum address the transaction is directed to.

    • method: string

      The smart contract member in which to invoke.

    • Default value parameters: any[] = []
    • Default value options: CallOptions = {}

    Returns Promise<any>

    Return value of the invoked smart contract member or an error object if the call failed.

trx

  • trx(address: string, method: string, parameters?: any[], options?: CallOptions): Promise<any>
  • This is a generic method for invoking JSON RPC's eth_sendTransaction with Ethers.js. Use this method to create a transaction that invokes a smart contract method. Returns an Ethers.js TransactionResponse object.

    example
    const oneEthInWei = '1000000000000000000';
    const vBnbAddress = '0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5';
    const provider = window.ethereum;
    
    (async function() {
      console.log('Supplying BNB to the Venus Protocol...');
    
      // Mint some vBNB by supplying BNB to the Venus Protocol
      const trx = await Venus.eth.trx(
        vBnbAddress,
        'function mint() payable',
        [],
        {
          provider,
          value: oneEthInWei
        }
      );
    
      // const result = await trx.wait(1); // JSON object of trx info, once mined
    
      console.log('Ethers.js transaction object', trx);
    })().catch(console.error);

    Parameters

    • address: string

      The Ethereum address the transaction is directed to.

    • method: string

      The smart contract member in which to invoke.

    • Default value parameters: any[] = []
    • Default value options: CallOptions = {}

    Returns Promise<any>

    Returns an Ethers.js TransactionResponse object or an error object if the transaction failed.