Web3 API
web3.eth
The web3-eth
package allows you to interact with an Ethereum blockchain and Ethereum smart contracts.
Note on checksum addresses
All Ethereum addresses returned by functions of this package are returned as checksum addresses. This means some letters are uppercase and some are lowercase. Based on that it will calculate a checksum for the address and prove its correctness. Incorrect checksum addresses will throw an error when passed into functions. If you want to circumvent the checksum check you can make an address all lower- or uppercase.
Example
Subscribe
For web3.eth.subscribe
see the Subscribe reference documentation.
Contract
For web3.eth.Contract
see the Contract reference documentation.
Iban
For web3.eth.Iban
see the Iban reference documentation.
personal
For web3.eth.personal
see the personal reference documentation.
accounts
For web3.eth.accounts
see the accounts reference documentation.
ens
For web3.eth.ens
see the ENS reference documentation.
abi
For web3.eth.abi
see the ABI reference documentation.
net
For web3.eth.net
see the net reference documentation.
setProvider
Will change the provider for its module.
❗️When called on the umbrella package web3
it will also set the provider for all sub modules web3.eth
, web3.shh
, etc. EXCEPT web3.bzz
which needs a separate provider at all times.
Example: Local Geth Node
Example: Remote Node Provider
providers
Contains the current available providers.
Value
Object
with the following providers:
Object
-HttpProvider
: HTTP provider, does not support subscriptions.
Object
-WebsocketProvider
: The Websocket provider is the standard for usage in legacy browsers.
Object
-IpcProvider
: The IPC provider is used node.js dapps when running a local node. Gives the most secure connection.
Example
Configuration
More information for the Http and Websocket provider modules can be found here:
givenProvider
When using web3.js in an Ethereum compatible browser, it will set with the current native provider by that browser. Will return the given provider by the (browser) environment, otherwise null
.
Returns
Object
: The given provider set or null
;
Example
currentProvider
Will return the current provider, otherwise null
.
Returns
Object
: The current provider set or null
.
Example
BatchRequest
Class to create and execute batch requests.
Parameters
none
Returns
Object
: With the following methods:
add(request)
: To add a request object to the batch call.
execute()
: Will execute the batch request.
Example
extend
Allows extending the web3 modules.
Note
You also have *.extend.formatters
as additional formatter functions to be used for input and output formatting. Please see the source file for function details.
Parameters
methods
-Object
: Extension object with array of methods description objects as follows:property
-String
: (optional) The name of the property to add to the module. If no property is set it will be added to the module directly.methods
-Array
: The array of method descriptions:name
-String
: Name of the method to add.call
-String
: The RPC method name.params
-Number
: (optional) The number of parameters for that function. Default 0.inputFormatter
-Array
: (optional) Array of inputformatter functions. Each array item responds to a function parameter, so if you want some parameters not to be formatted, add anull
instead.outputFormatter - ``Function
: (optional) Can be used to format the output of the method.
Returns
Object
: The extended module.
Example
defaultAccount
This default address is used as the default "from"
property, if no "from"
property is specified in for the following methods:
web3.eth.call()
new web3.eth.Contract() -> myContract.methods.myMethod().call()
new web3.eth.Contract() -> myContract.methods.myMethod().send()
Property
String
- 20 Bytes: Any ethereum address. You should have the private key for that address in your node or keystore. (Default is undefined
)
Example
defaultBlock
The default block is used for certain methods. You can override it by passing in the defaultBlock as last parameter. The default value is "latest"
.
web3.eth.getBalance()
web3.eth.getCode()
web3.eth.getStorageAt()
web3.eth.call()
new web3.eth.Contract() -> myContract.methods.myMethod().call()
Property
Default block parameters can be one of the following:
Number|BN|BigNumber
: A block number"earliest"
-String
: The genesis block"latest"
-String
: The latest block (current head of the blockchain)"pending"
-String
: The currently mined block (including pending transactions)"finalized"
-String
: (For POS networks) The finalized block is one which has been accepted as canonical by >2/3 of validators."safe"
-String
: (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work networks latest blocks.
Default is "latest"
Example
defaultHardfork
The default hardfork property is used for signing transactions locally.
Property
The default hardfork property can be one of the following:
"chainstart"
-String
"homestead"
-String
"dao"
-String
"tangerineWhistle"
-String
"spuriousDragon"
-String
"byzantium"
-String
"constantinople"
-String
"petersburg"
-String
"istanbul"
-String
"berlin"
-String
"london"
-String
Default is "london"
Example
defaultChain
The default chain property is used for signing transactions locally.
Property
The default chain property can be one of the following:
"mainnet"
-String
"goerli"
-String
"kovan"
-String
"rinkeby"
-String
"ropsten"
-String
Default is "mainnet"
Example
defaultCommon
The default common property is used for signing transactions locally.
Property
The default common property does contain the following Common
object:
customChain
-Object
: The custom chain propertiesname
-string
: (optional) The name of the chainnetworkId
-number
: Network ID of the custom chainchainId
-number
: Chain ID of the custom chain
baseChain
-string
: (optional)mainnet
,goerli
,kovan
,rinkeby
, orropsten
hardfork
-string
: (optional)chainstart
,homestead
,dao
,tangerineWhistle
,spuriousDragon
,byzantium
,constantinople
,petersburg
,istanbul
,berlin
, orlondon
Default is undefined
.
Example
transactionBlockTimeout
The transactionBlockTimeout
is used over socket-based connections. This option defines the amount of new blocks it should wait until the first confirmation happens, otherwise the PromiEvent rejects with a timeout error.
Returns
number
: The current value of transactionBlockTimeout (default: 50)
Example
blockHeaderTimeout
The blockHeaderTimeout
is used over socket-based connections. This option defines the amount seconds it should wait for “newBlockHeaders” event before falling back to polling to fetch transaction receipt.
Returns
number
: The current value of blockHeaderTimeout (default: 10 seconds)
Example
transactionConfirmationBlocks
This defines the number of blocks it requires until a transaction is considered confirmed.
Returns
number
: The current value of transactionConfirmationBlocks (default: 24)
Example
transactionPollingTimeout
The transactionPollingTimeout
is used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. Note: If this method times out, the transaction may still be pending.
Returns
number
: The current value of transactionPollingTimeout (default: 750)
Example
transactionPollingInterval
The transactionPollingInterval
is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network.
Returns
number
: The current value of transactionPollingInterval (default: 1000ms)
handleRevert
The handleRevert
options property defaults to false
and returns the revert reason string if enabled for the following methods:
web3.eth.call()
Note
The revert reason string and signature exist as a property on the returned error.
Returns
boolean
: The current value of handleRevert
(default: false)
Example
maxListenersWarningThreshold
This defines the threshold above which a warning about the number of event listeners attached to a provider which supports sockets subscriptions will be written to the console. You may see this warning if you call setProvider
on large numbers of Web3 contract objects.
Returns
number
: The current value of maxListenersWarningThreshold (default: 100)
Example
getProtocolVersion
Returns the ethereum protocol version of the node.
Returns
Promise
returns String
: the protocol version.
Example
isSyncing
Checks if the node is currently syncing and returns either a syncing object, or false
.
Returns
Promise
returns Object|Boolean
- A sync object when the node is currently syncing or false
:
startingBlock
-Number
: The block number where the sync started.
currentBlock
-Number
: The block number where the node is currently synced to.
highestBlock
-Number
: The estimated block number to sync to.
knownStates
-Number
: The number of estimated states to download.
pulledStates
-Number
: The number of already downloaded states.
Example
getCoinbase
Returns the coinbase address to which mining rewards will go.
Returns
Promise
returns String
- bytes 20: The coinbase address set in the node for mining rewards.
Example
isMining
Checks whether the node is mining or not.
Returns
Promise
returns Boolean
: true
if the node is mining, otherwise false
.
Example
getHashrate
Returns the number of hashes per second that the node is mining with.
Returns
Promise
returns Number
: Number of hashes per second.
Example
getGasPrice
Returns the current gas price oracle. The gas price is determined by the last few blocks median gas price.
Returns
Promise
returns String
- Number string of the current gas price in wei.
See the A note on dealing with big numbers in JavaScript.
Example
getFeeHistory
Transaction fee history Returns base fee per gas and transaction effective priority fee per gas history for the requested block range if available. The range between headBlock-4 and headBlock is guaranteed to be available while retrieving data from the pending block and older history are optional to support. For pre-EIP-1559 blocks the gas prices are returned as rewards and zeroes are returned for the base fee per gas.
Parameters
String|Number|BN|BigNumber
- Number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. Less than requested may be returned if not all blocks are available.String|Number|BN|BigNumber
- Highest number block of the requested range.Array of numbers
- A monotonically increasing list of percentile values to sample from each block’s effective priority fees per gas in ascending order, weighted by gas used. Example: [“0”, “25”, “50”, “75”, “100”] or [“0”, “0.5”, “1”, “1.5”, “3”, “80”]Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- Fee history for the returned block range. The object:
Number
oldestBlock - Lowest number block of the returned range.Array of strings
baseFeePerGas - An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.Array of numbers
gasUsedRatio - An array of block gas used ratios. These are calculated as the ratio of gasUsed and gasLimit.Array of string arrays
reward - An array of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty.
getAccounts
Returns a list of accounts the node controls.
Returns
Promise
returns Array
- An array of addresses controlled by node.
Example
getBlockNumber
Returns the current block number.
Returns
Promise
returns Number
- The number of the most recent block.
Example
getBalance
Get the balance of an address at a given block.
Parameters
String
- The address to get the balance of.Number|String|BN|BigNumber
- (optional) If you pass this parameter it will not use the default block set with web3.eth.defaultBlock. Pre-defined block numbers as"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns String
- The current balance for the given address in wei.
See the A note on dealing with big numbers in JavaScript.
Example
getStorageAt
Get the storage at a specific position of an address.
Parameters
String
- The address to get the storage from.Number|String|BN|BigNumber
- The index position of the storage.Number|String|BN|BigNumber
- (optional) If you pass this parameter it will not use the default block set with web3.eth.defaultBlock. Pre-defined block numbers as"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns String
- The value in storage at the given position.
Example
getCode
Get the code at a specific address.
Parameters
String
- The address to get the code from.Number|String|BN|BigNumber
- (optional) If you pass this parameter it will not use the default block set with web3.eth.defaultBlock. Pre-defined block numbers as"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns String
- The data at given address address
.
Example
getBlock
Returns a block matching the block number or block hash.
Parameters
String|Number|BN|BigNumber
- The block number or block hash. Or the string"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
as in the default block parameter.Boolean
- (optional, defaultfalse
) If specifiedtrue
, the returned block will contain all transactions as objects. Iffalse
it will only contains the transaction hashes.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- The block object:
number
-Number
: The block number.null
if a pending block.
hash
32 Bytes -String
: Hash of the block.null
if a pending block.
parentHash
32 Bytes -String
: Hash of the parent block.
baseFeePerGas
-Number
: Minimum to be charged to send a transaction on the network
codeword
-String
: Hash of the generated proof-of-work.null
if a pending block.
nonce
8 Bytes -String
: Hash of the generated proof-of-work.null
if a pending block.
sha3Uncles
32 Bytes -String
: SHA3 of the uncles data in the block.
logsBloom
256 Bytes -String
: The bloom filter for the logs of the block.null
if a pending block.
transactionsRoot
32 Bytes -String
: The root of the transaction trie of the block.
stateRoot
32 Bytes -String
: The root of the final state trie of the block.
miner
-String
: The address of the beneficiary to whom the mining rewards were given.
difficulty
-String
: Integer of the difficulty for this block.
totalDifficulty
-String
: Integer of the total difficulty of the chain until this block.
extraData
-String
: The “extra data” field of this block.
size
-Number
: Integer the size of this block in bytes.
gasLimit
-Number
: The maximum gas allowed in this block.
gasUsed
-Number
: The total used gas by all transactions in this block.
timestamp
-Number
: The unix timestamp for when the block was collated.
transactions
-Array
: Array of transaction objects, or 32 Bytes transaction hashes depending on thereturnTransactionObjects
parameter.
uncles
-Array
: Array of uncle hashes.
Example
getBlockTransactionCount
Returns the number of transaction in a given block.
Parameters
String|Number|BN|BigNumber
- The block number or hash. Or the string"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
as in the default block parameter.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Number
- The number of transactions in the given block.
Example
getBlockUncleCount
Returns the number of uncles in a block from a block matching the given block hash.
Parameters
String|Number|BN|BigNumber
- The block number or hash. Or the string"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
as in the default block parameter.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Number
- The number of transactions in the given block.
Example
getUncle
Returns a blocks uncle by a given uncle index position.
Parameters
String|Number|BN|BigNumber
- The block number or hash. Or the string"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
as in the default block parameter.Number
- The index position of the uncle.Boolean
- (optional, defaultfalse
) If specifiedtrue
, the returned block will contain all transactions as objects. By default it isfalse
so, there is no need to explictly specify false. And, iffalse
it will only contains the transaction hashes.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- the returned uncle. For a return value see web3.eth.getBlock().
Note
An uncle doesn’t contain individual transactions.
Example
getTransaction
Returns a transaction matching the given transaction hash.
Parameters
String
- The transaction hash.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- A transaction object its hash transactionHash
:
hash
32 Bytes -String
: Hash of the transaction.
nonce
-Number
: The number of transactions made by the sender prior to this one.
blockHash
32 Bytes -String
: Hash of the block where this transaction was in.null
if pending.
blockNumber
-Number
: Block number where this transaction was in.null
if pending.
transactionIndex
-Number
: Integer of the transactions index position in the block.null
if pending.
from
-String
: Address of the sender.
to
-String
: Address of the receiver.null
if it’s a contract creation transaction.
value
-String
: Value transferred in wei.
gasPrice
-String
: Gas price provided by the sender in wei.
gas
-Number
: Gas provided by the sender.
input
-String
: The data sent along with the transaction.
Example
getPendingTransactions
Returns a list of pending transactions.
Parameters
Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise<object[]>
- Array of pending transactions:
hash
32 Bytes -String
: Hash of the transaction.
nonce
-Number
: The number of transactions made by the sender prior to this one.
blockHash
32 Bytes -String
: Hash of the block where this transaction was in.null
if pending.
blockNumber
-Number
: Block number where this transaction was in.null
if pending.
transactionIndex
-Number
: Integer of the transactions index position in the block.null
if pending.
from
-String
: Address of the sender.
to
-String
: Address of the receiver.null
when it’s a contract creation transaction.
value
-String
: Value transferred in wei.
gasPrice
-String
: The wei per unit of gas provided by the sender in wei.
gas
-Number
: Gas provided by the sender.
input
-String
: The data sent along with the transaction.
Example
getTransactionFromBlock
Returns a transaction based on a block hash or number and the transaction’s index position.
Parameters
String|Number|BN|BigNumber
- A block number or hash. Or the string"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
as in the default block parameter.Number
- The transaction’s index position.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- A transaction object, see web3.eth.getTransaction:
Example
getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Note
The receipt is not available for pending transactions and returns null
.
Parameters
String
- The transaction hash.String
- (optional) Thehex
keyword can be passed as second argument, in order to format in hex, values that would beNumber
otherwise.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- A transaction receipt object, or null
if no receipt was found:
status
-Boolean
:TRUE
if the transaction was successful,FALSE
if the EVM reverted the transaction.
blockHash
32 Bytes -String
: Hash of the block where this transaction was in.
blockNumber
-Number
(orhex String
): Block number where this transaction was in.
transactionHash
32 Bytes -String
: Hash of the transaction.
transactionIndex
-Number
(orhex String
): Integer of the transactions index position in the block.
from
-String
: Address of the sender.
to
-String
: Address of the receiver.null
when it’s a contract creation transaction.
contractAddress
-String
: The contract address created, if the transaction was a contract creation, otherwisenull
.
cumulativeGasUsed
-Number
(orhex String
): The total amount of gas used when this transaction was executed in the block.
gasUsed
-Number
(orhex String
): The amount of gas used by this specific transaction alone.
logs
-Array
: Array of log objects, which this transaction generated.
effectiveGasPrice
-Number
(orhex String
): The actual value per gas deducted from the senders account. Before EIP-1559, this is equal to the transaction’s gas price. After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas).
Example
getTransactionCount
Get the number of transactions sent from this address.
Parameters
String
- The address to get the numbers of transactions from.Number|String|BN|BigNumber
- (optional) If you pass this parameter it will not use the default block set with web3.eth.defaultBlock. Pre-defined block numbers as"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Number
- The number of transactions sent from the given address.
Example
sendTransaction
Sends a transaction to the network.
Parameters
Object
- The transaction object to send:from
-String|Number
: The address for the sending account. Uses the web3.eth.defaultAccount property, if not specified. Or an address or index of a local wallet in web3.eth.accounts.wallet.to
-String
: (optional) The destination address of the message, left undefined for a contract-creation transaction.value
-Number|String|BN|BigNumber
: (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.gas
-Number
: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).gasPrice
-Number|String|BN|BigNumber
: (optional) The price of gas for this transaction in wei, defaults to web3.eth.gasPrice.type
-Number|String|BN|BigNumber
: (optional) A positive unsigned 8-bit number between 0 and 0x7f that represents the type of the transaction.maxFeePerGas
-Number|String|BN
: (optional, defaulted to(2 * block.baseFeePerGas) + maxPriorityFeePerGas
) The maximum fee per gas that the transaction is willing to pay in totalmaxPriorityFeePerGas
-Number|String|BN
(optional, defaulted to2.5 Gwei
) The maximum fee per gas to give miners to incentivize them to include the transaction (Priority fee)accessList
-List of hexstrings
(optional) a list of addresses and storage keys that the transaction plans to accessdata
-String
: (optional) Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code.nonce
-Number
: (optional) Integer of the nonce. This allows to overwrite your own pending transactions that use the same nonce.chain
-String
: (optional) Defaults tomainnet
.hardfork
-String
: (optional) Defaults tolondon
.common
-Object
: (optional) The common objectcustomChain
-Object
: The custom chain propertiesname
-string
: (optional) The name of the chainnetworkId
-number
: Network ID of the custom chainchainId
-number
: Chain ID of the custom chain
baseChain
-string
: (optional)mainnet
,goerli
,kovan
,rinkeby
, orropsten
hardfork
-string
: (optional)chainstart
,homestead
,dao
,tangerineWhistle
,spuriousDragon
,byzantium
,constantinople
,petersburg
,istanbul
,berlin
, orlondon
callback
-Function
: (optional) Optional callback, returns an error object as first parameter and the result as second.
Note
The from
property can also be an address or index from the web3.eth.accounts.wallet. It will then sign locally using the private key of that account, and send the transaction via web3.eth.sendSignedTransaction(). If the properties chain
and hardfork
or common
are not set, Web3 will try to set appropriate values by querying the network for its chainId and networkId.
Returns
The callback will return the 32 bytes transaction hash.
PromiEvent
: A promise combined event emitter. Resolves when the transaction receipt is available. The following events are also available:
sending
returnspayload: Object
: Fired immediately before transmitting the transaction request.sent
returnspayload: Object
: Fired immediately after the request body has been written to the client, but before the transaction hash is received."transactionHash"
returnstransactionHash: String
: Fired when the transaction hash is available."receipt"
returnsreceipt: Object
: Fired when the transaction receipt is available."confirmation"
returnsconfirmationNumber: Number
,receipt: Object
,latestBlockHash: String
: Fired for every confirmation up to the 12th confirmation. Receives the confirmation number as the first and the receipt as the second argument. Fired from confirmation 0 on, which is the block where it’s mined.
"error"
returns error: Error
: Fired if an error occurs during sending. If the transaction was rejected by the network with a receipt, the receipt will be available as a property on the error object.
Example
sendSignedTransaction
Sends an already signed transaction, generated for example using web3.eth.accounts.signTransaction.
Parameters
String
- Signed transaction data in HEX formatFunction
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
PromiEvent
: A promise combined event emitter. Resolves when the transaction receipt is available.
Please see the return values for web3.eth.sendTransaction for details.
Example
Note
When using ethereumjs-tx@2.0.0 if you don’t specify the parameter chain it will use mainnet by default.
sign
Signs data using a specific account. This account needs to be unlocked.
Parameters
String
- Data to sign. If it is a string it will be converted using web3.utils.utf8ToHex.String|Number
- Address to sign data with. Can be an address or the index of a local wallet in web3.eth.accounts.wallet.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns String
- The signature.
Example
signTransaction
Signs a transaction. This account needs to be unlocked.
Parameters
Object
- The transaction data to sign. See web3.eth.sendTransaction() for more.String
- Address to sign transaction with.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Object
- The RLP encoded transaction. The raw
property can be used to send the transaction using web3.eth.sendSignedTransaction.
Example
call
Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.
Parameters
Object
- A transaction object, see web3.eth.sendTransaction. For calls thefrom
property is optional however it is highly recommended to explicitly set it or it may default to address(0) depending on your node or provider.Number|String|BN|BigNumber
- (optional) If you pass this parameter it will not use the default block set with web3.eth.defaultBlock. Pre-defined block numbers as"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns String
: The returned data of the call, e.g. a smart contract functions return value.
Example
estimateGas
Executes a message call or transaction and returns the amount of the gas used. Note: You must specify a from
address otherwise you may experience odd behavior.
Parameters
Object
- A transaction object, see web3.eth.sendTransaction with the difference that for calls thefrom
property is optional as well.Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Number
- the used gas for the simulated call/transaction.
Example
getPastLogs
Gets past logs, matching the given options.
Parameters
Object
- The filter options as follows:
fromBlock
-Number|String
: The number of the earliest block (or any of block tag"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used). By default"latest"
.
toBlock
-Number|String
: The number of the latest block (or any of block tag"earliest"
,"latest"
,"pending"
,"safe"
or"finalized"
can also be used). By default"latest"
.
address
-String|Array
: An address or a list of addresses to only get logs from particular account(s).
topics
-Array
: An array of values which must each appear in the log entries. The order is important, if you want to leave topics out usenull
, e.g.[null, '0x12...']
. You can also pass an array for each topic with options for that topic e.g.[null, ['option1', 'option2']]
Returns
Promise
returns Array
- Array of log objects.
The structure of the returned event Object
in the Array
looks as follows:
address
-String
: From which this event originated from.data
-String
: The data containing non-indexed log parameter.topics
-Array
: An array with max 4 32 Byte topics, topic 1-3 contains indexed parameters of the log.logIndex
-Number
: Integer of the event index position in the block.transactionIndex
-Number
: Integer of the transaction’s index position, the event was created in.transactionHash
32 Bytes -String
: Hash of the transaction this event was created in.blockHash
32 Bytes -String
: Hash of the block where this event was created in.null
if still pending.blockNumber
-Number
: The block number where this log was created in.null
if still pending.
Example
getWork
Gets work for miners to mine on. Returns the hash of the current block, the seedHash, and the boundary condition to be met (“target”).
Parameters
Function
- (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise
returns Array
- the mining work with the following structure:
String
32 Bytes - at index 0: current block header pow-hash
String
32 Bytes - at index 1: the seed hash used for the DAG.
String
32 Bytes - at index 2: the boundary condition (“target”), 2^256 / difficulty.
Example
submitWork
Used for submitting a proof-of-work solution.
Parameters
String
8 Bytes: The nonce found (64 bits)String
32 Bytes: The header’s pow-hash (256 bits)