Web3Client class
Class for sending requests over an HTTP JSON-RPC API endpoint to Core 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, String username, String password, {SocketConnector? socketConnector})
-
Starts a client that connects to a JSON rpc API, available at
url. ThehttpClientwill 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. Web3dart
will use the
StreamChannelreturned 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(
{XCBAddress? sender, required DeployedContract contract, required ContractFunction function, required List params, BlockNum? atBlock}) → Future< List> -
Calls a
functiondefined in the smartcontractand returns it's result. -
callRaw(
{XCBAddress? sender, required XCBAddress contract, required Uint8List data, BlockNum? atBlock}) → Future< String> - Sends a raw method call to a smart contract.
-
coinbaseAddress(
) → Future< XCBAddress> -
credentialsFromPrivateKey(
String privateKey) → Future< XCBPrivateKey> -
Constructs a new Credentials with the provided
privateKeyby using an XCBPrivateKey. -
dispose(
) → Future< void> - Closes resources managed by this client, such as the optional background isolate for calculations and managed streams.
-
estimateEnergy(
{XCBAddress? sender, XCBAddress? to, XCBAmount? value, BigInt? amountOfEnergy, XCBAmount? energyPrice, Uint8List? data, BlockNum? atBlock}) → Future< BigInt> - Estimate the amount of energy that would be necessary if the transaction was sent via sendTransaction. Note that the estimate may be significantly higher than the amount of energy actually used by the transaction.
-
events(
FilterOptions options) → Stream< FilterEvent> -
Listens for logs emitted from transactions. The
optionscan be used to apply additional filters. -
getBalance(
XCBAddress address, {BlockNum? atBlock}) → Future< XCBAmount> - 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.
-
getClientVersion(
) → Future< String> - Returns the version of the client we're sending requests to.
-
getCode(
XCBAddress address, {BlockNum? atBlock}) → Future< Uint8List> -
Gets the code of a contract at the specified
address -
getCoreProtocolVersion(
) → Future< int> - Returns the version of the Core-protocol the client is using.
-
getEnergyPrice(
) → Future< XCBAmount> - Returns the amount of Core typically needed to pay for one unit of energy.
-
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 Core nodes currently connected to the client.
-
getStorage(
XCBAddress address, BigInt position, {BlockNum? atBlock}) → Future< Uint8List> -
Gets an element from the storage of the contract with the specified
addressat the specifiedposition. See https://github.com/ethereum/wiki/wiki/JSON-RPC#xcb_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(
XCBAddress 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, {required int networkId}) → Future< String> -
Signs the given transaction using the keys supplied in the
credobject to upload it to the client so that it can be executed. -
signTransaction(
Credentials cred, Transaction transaction, {required int networkId}) → Future< Uint8List> -
Signs the
transactionwith the credentialscred. The transaction will not be sent. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited