Links

Web3 API

Signing a transaction

There's an example for signing a transaction in case there's a need to update the state of blockchain by creating a transaction. Following is an example that updates the state variable of a deployed contract.
  1. 1.
    In this case, we call the function setGreeting and store the transaction in a variable tx
  2. 2.
    We then pass the tx along with contract details
  3. 3.
    The function signTransaction creates a block of data containing all the necessary information like gas price, contract information, network information, etc. and calls the web3 method to sign the transaction.

Gas Price

We have added two methods to fetch the gas price
  1. 1.
    web3.eth.getGasPrice() gets the latest gas price
  2. 2.
    web3.eth.getFeeHistory() gets the gas price using custom parameters like
    1. 1.
      No. of blocks (the amount of previous blocks it searches)
    2. 2.
      String/BN value to request the newest block in the requested range
    3. 3.
      Percentile options (1-99th percentile)
    4. 4.
      CallBack
The getFeeHistory() will calculate an average of the blocks (mentioned in first parameter) and figure out the best gas prices based on the percentile for slow/average/fast options. This API also returns the baseFeePerGas (introduced after EIP-1559) which is added to the gas prices outputted by the above call.
Rest of the Web3 API calls and examples on Fantom: https://github.com/Fantom-foundation/web3-methods/wiki