Web3Client class

Class for sending requests over an HTTP JSON-RPC API endpoint to Ethereum clients. This library won't use the accounts feature of clients to use them to create transactions, you will instead have to obtain private keys of accounts yourself.

Constructors

Web3Client(String url, Client httpClient, {SocketConnector? socketConnector})
Starts a client that connects to a JSON rpc API, available at url. The httpClient will be used to send requests to the rpc server. Am isolate will be used to perform expensive operations, such as signing transactions or computing private keys.
Web3Client.custom(RpcService rpc, {SocketConnector? socketConnector})

Properties

hashCode int
The hash code for this object.
no setterinherited
printErrors bool
Whether errors, handled or not, should be printed to the console.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
socketConnector SocketConnector?
Some ethereum nodes support an event channel over websockets. dart_web3 will use the StreamChannel returned by this function as a socket to send event requests and parse responses. Can be null, in which case a polling implementation for events will be used.
final

Methods

addedBlocks() Stream<String>
Listens for new blocks that are added to the chain. The stream will emit the hexadecimal hash of the block after it has been added.
call({EthereumAddress? sender, required DeployedContract contract, required ContractFunction function, required List params, BlockNum? atBlock}) Future<List>
Calls a function defined in the smart contract and returns it's result.
callRaw({EthereumAddress? sender, required EthereumAddress contract, required Uint8List data, BlockNum? atBlock}) Future<String>
Sends a raw method call to a smart contract.
coinbaseAddress() Future<EthereumAddress>
credentialsFromPrivateKey(String privateKey) Future<EthPrivateKey>
Constructs a new Credentials with the provided privateKey by using an EthPrivateKey.
dispose() Future<void>
Closes resources managed by this client, such as the optional background isolate for calculations and managed streams.
estimateGas({EthereumAddress? sender, EthereumAddress? to, EtherAmount? value, BigInt? amountOfGas, EtherAmount? gasPrice, EtherAmount? maxPriorityFeePerGas, EtherAmount? maxFeePerGas, Uint8List? data, BlockNum? atBlock}) Future<BigInt>
Estimate the amount of gas that would be necessary if the transaction was sent via sendTransaction. Note that the estimate may be significantly higher than the amount of gas actually used by the transaction.
events(FilterOptions options) Stream<FilterEvent>
Listens for logs emitted from transactions. The options can be used to apply additional filters.
getBalance(EthereumAddress address, {BlockNum? atBlock}) Future<EtherAmount>
Gets the balance of the account with the specified address.
getBlockInformation({String blockNumber = 'latest', bool isContainFullObj = true}) Future<BlockInformation>
getBlockNumber() Future<int>
Returns the number of the most recent block on the chain.
getChainId() Future<BigInt>
getClientVersion() Future<String>
Returns the version of the client we're sending requests to.
getCode(EthereumAddress address, {BlockNum? atBlock}) Future<Uint8List>
Gets the code of a contract at the specified address
getEtherProtocolVersion() Future<int>
Returns the version of the Ethereum-protocol the client is using.
getGasPrice() Future<EtherAmount>
Returns the amount of Ether typically needed to pay for one unit of gas.
getLogs(FilterOptions options) Future<List<FilterEvent>>
Returns all logs matched by the filter in options.
getMiningHashrate() Future<int>
Returns the amount of hashes per second the connected node is mining with.
getNetworkId() Future<int>
Returns the id of the network the client is currently connected to.
getPeerCount() Future<int>
Returns the amount of Ethereum nodes currently connected to the client.
getStorage(EthereumAddress address, BigInt position, {BlockNum? atBlock}) Future<Uint8List>
Gets an element from the storage of the contract with the specified address at the specified position. See https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat for more details. This function allows specifying a custom block mined in the past to get historical data. By default, BlockNum.current will be used.
getSyncStatus() Future<SyncInformation>
Returns an object indicating whether the node is currently synchronising with its network.
getTransactionByHash(String transactionHash) Future<TransactionInformation>
Returns the information about a transaction requested by transaction hash transactionHash.
getTransactionCount(EthereumAddress address, {BlockNum? atBlock}) Future<int>
Gets the amount of transactions issued by the specified address.
getTransactionReceipt(String hash) Future<TransactionReceipt?>
Returns an receipt of a transaction based on its hash.
isListeningForNetwork() Future<bool>
Returns true if the node is actively listening for network connections.
isMining() Future<bool>
Returns true if the connected client is currently mining, false if not.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pendingTransactions() Stream<String>
Listens for pending transactions as they are received by the connected node. The stream will emit the hexadecimal hash of the pending transaction.
sendRawTransaction(Uint8List signedTransaction) Future<String>
Sends a raw, signed transaction.
sendTransaction(Credentials cred, Transaction transaction, {int? chainId = 1, bool fetchChainIdFromNetworkId = false}) Future<String>
Signs the given transaction using the keys supplied in the cred object to upload it to the client so that it can be executed.
signTransaction(Credentials cred, Transaction transaction, {int? chainId = 1, bool fetchChainIdFromNetworkId = false}) Future<Uint8List>
Signs the transaction with the credentials cred. The transaction will not be sent.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited