Web3j Ethereum Blockchain
Since Camel 2.22
Both producer and consumer are supported
The Ethereum blockchain component uses the web3j client API and allows you to interact with Ethereum compatible nodes such as:
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web3j</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Web3j Ethereum Blockchain component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
A comma separated list of the contract addresses whose logs the ETH_LOG_OBSERVABLE consumer receives. The ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer ignore this option: they take the addresses only from the CamelWeb3jAddresses header, as a List. | String | ||
The configuration that the endpoints of this component start from. Each endpoint uses a copy, and the options set on the endpoint override it. | Web3jConfiguration | ||
The address that the transaction is sent from, for ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION, or the Whisper identity of the sender for SHH_POST. | String | ||
The first block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by the ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer, and the ETH_LOG_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE and REPLAY_TRANSACTIONS_OBSERVABLE operations of the consumer. | latest | String | |
Whether a block holds the full transaction objects (true) or only the hashes of its transactions (false). For ETH_GET_BLOCK_BY_HASH and ETH_GET_BLOCK_BY_NUMBER, and the BLOCK_OBSERVABLE and REPLAY_BLOCKS_OBSERVABLE operations of the consumer. | false | boolean | |
The maximum amount of gas that the transaction can use, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION. When not set, the node chooses it. | BigInteger | ||
Operation to use. The producer needs an operation, set with this option or the CamelWeb3jOperation header. The consumer needs one of the observable operations: ETH_LOG_OBSERVABLE, ETH_BLOCK_HASH_OBSERVABLE, ETH_PENDING_TRANSACTION_HASH_OBSERVABLE, TRANSACTION_OBSERVABLE, PENDING_TRANSACTION_OBSERVABLE, BLOCK_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE or REPLAY_TRANSACTIONS_OBSERVABLE. | transaction | String | |
A comma separated list of the public keys of the Quorum nodes that receive the private transaction that QUORUM_ETH_SEND_TRANSACTION sends. | String | ||
Whether the endpoint builds a Quorum client instead of a Web3j client. The QUORUM_ETH_SEND_TRANSACTION, QUORUM_NODE_INFO and QUORUM_GET_PRIVATE_PAYLOAD operations need it. Not used when the web3j option is set. | false | boolean | |
The address that the transaction is sent to, for ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION (not set for a contract creation), or the Whisper identity of the receiver for SHH_POST. | String | ||
The last block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by the ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer, and the ETH_LOG_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE and REPLAY_TRANSACTIONS_OBSERVABLE operations of the consumer. | latest | String | |
A comma separated list of the log topics that the ETH_LOG_OBSERVABLE consumer filters on, matched by position: the first entry matches the first topic of a log, and so on, and an empty entry matches any topic at its position. The ETH_NEW_FILTER, ETH_GET_LOGS, SHH_POST and SHH_NEW_FILTER operations of the producer ignore this option: they take the topics only from the CamelWeb3jTopics header, as a List. | String | ||
The Web3j client to use, instead of the one that the endpoint builds from the node address. When set, the node address and the quorumAPI option are not used: set a Quorum client for the QUORUM_ETH_SEND_TRANSACTION, QUORUM_NODE_INFO and QUORUM_GET_PRIVATE_PAYLOAD operations. | Web3j | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
The address of the account or contract, for ETH_GET_BALANCE, ETH_GET_STORAGE_AT, ETH_GET_TRANSACTION_COUNT, ETH_GET_CODE and ETH_SIGN, or the Whisper identity for SHH_HAS_IDENTITY and SHH_ADD_TO_GROUP. | String | ||
The block that the operation reads the state at: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by ETH_GET_BALANCE, ETH_GET_STORAGE_AT, ETH_GET_TRANSACTION_COUNT, ETH_GET_CODE, ETH_CALL, ETH_GET_BLOCK_BY_NUMBER, ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER, ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER, ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX. | latest | String | |
The hash of the block, for ETH_GET_BLOCK_BY_HASH, ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH, ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH, ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX. | String | ||
A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE. | String | ||
The data, as a hex string. For ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION, the data of the transaction: the compiled code of a contract to create, or the hash of the method signature and the encoded parameters of a contract call. For SHH_POST, the payload of the Whisper message. For SHH_NEW_FILTER, the Whisper identity that the messages are sent to. | String | ||
The name of the local database of the node, for the DB_PUT_STRING, DB_GET_STRING, DB_PUT_HEX and DB_GET_HEX operations. | String | ||
The id of the filter, as a decimal number, for ETH_UNINSTALL_FILTER, ETH_GET_FILTER_CHANGES, ETH_GET_FILTER_LOGS, SHH_UNINSTALL_FILTER, SHH_GET_FILTER_CHANGES and SHH_GET_MESSAGES. | BigInteger | ||
The price in wei of each unit of gas, for ETH_SEND_TRANSACTION and ETH_CALL. When not set, the node chooses it. | BigInteger | ||
The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes. | String | ||
The proof-of-work hash of the block header (256 bits), as a hex string, for ETH_SUBMIT_WORK. | String | ||
The index of the transaction or the uncle in the block, as a decimal number, for ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX, ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX, ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX. | BigInteger | ||
The key in the local database of the node, for the DB_PUT_STRING, DB_GET_STRING, DB_PUT_HEX and DB_GET_HEX operations. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK. | String | ||
The nonce. For ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION, the nonce of the transaction as a decimal number; when not set, the node chooses it. For ETH_SUBMIT_WORK, the proof-of-work nonce found (64 bits), as a hex string. | String | ||
The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads, as a decimal number. | BigInteger | ||
The priority of the Whisper message that SHH_POST sends. | BigInteger | ||
The data that ETH_SIGN signs, as a hex string. The node signs it, with the Ethereum signed message prefix, with the key of the account in the address option. | String | ||
The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string: a message call or a contract creation. | String | ||
The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles. | String | ||
The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT. | String | ||
The time to live in seconds of the Whisper message that SHH_POST sends. | BigInteger | ||
The amount of wei that the transaction transfers, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION. | BigInteger | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Web3j Ethereum Blockchain endpoint is configured using URI syntax:
web3j:nodeAddress
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
A comma separated list of the contract addresses whose logs the ETH_LOG_OBSERVABLE consumer receives. The ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer ignore this option: they take the addresses only from the CamelWeb3jAddresses header, as a List. | String | ||
The address that the transaction is sent from, for ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION, or the Whisper identity of the sender for SHH_POST. | String | ||
The first block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by the ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer, and the ETH_LOG_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE and REPLAY_TRANSACTIONS_OBSERVABLE operations of the consumer. | latest | String | |
Whether a block holds the full transaction objects (true) or only the hashes of its transactions (false). For ETH_GET_BLOCK_BY_HASH and ETH_GET_BLOCK_BY_NUMBER, and the BLOCK_OBSERVABLE and REPLAY_BLOCKS_OBSERVABLE operations of the consumer. | false | boolean | |
The maximum amount of gas that the transaction can use, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION. When not set, the node chooses it. | BigInteger | ||
Operation to use. The producer needs an operation, set with this option or the CamelWeb3jOperation header. The consumer needs one of the observable operations: ETH_LOG_OBSERVABLE, ETH_BLOCK_HASH_OBSERVABLE, ETH_PENDING_TRANSACTION_HASH_OBSERVABLE, TRANSACTION_OBSERVABLE, PENDING_TRANSACTION_OBSERVABLE, BLOCK_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE or REPLAY_TRANSACTIONS_OBSERVABLE. | transaction | String | |
A comma separated list of the public keys of the Quorum nodes that receive the private transaction that QUORUM_ETH_SEND_TRANSACTION sends. | String | ||
Whether the endpoint builds a Quorum client instead of a Web3j client. The QUORUM_ETH_SEND_TRANSACTION, QUORUM_NODE_INFO and QUORUM_GET_PRIVATE_PAYLOAD operations need it. Not used when the web3j option is set. | false | boolean | |
The address that the transaction is sent to, for ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION (not set for a contract creation), or the Whisper identity of the receiver for SHH_POST. | String | ||
The last block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by the ETH_NEW_FILTER and ETH_GET_LOGS operations of the producer, and the ETH_LOG_OBSERVABLE, REPLAY_BLOCKS_OBSERVABLE and REPLAY_TRANSACTIONS_OBSERVABLE operations of the consumer. | latest | String | |
A comma separated list of the log topics that the ETH_LOG_OBSERVABLE consumer filters on, matched by position: the first entry matches the first topic of a log, and so on, and an empty entry matches any topic at its position. The ETH_NEW_FILTER, ETH_GET_LOGS, SHH_POST and SHH_NEW_FILTER operations of the producer ignore this option: they take the topics only from the CamelWeb3jTopics header, as a List. | String | ||
The Web3j client to use, instead of the one that the endpoint builds from the node address. When set, the node address and the quorumAPI option are not used: set a Quorum client for the QUORUM_ETH_SEND_TRANSACTION, QUORUM_NODE_INFO and QUORUM_GET_PRIVATE_PAYLOAD operations. | Web3j | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
The address of the account or contract, for ETH_GET_BALANCE, ETH_GET_STORAGE_AT, ETH_GET_TRANSACTION_COUNT, ETH_GET_CODE and ETH_SIGN, or the Whisper identity for SHH_HAS_IDENTITY and SHH_ADD_TO_GROUP. | String | ||
The block that the operation reads the state at: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Used by ETH_GET_BALANCE, ETH_GET_STORAGE_AT, ETH_GET_TRANSACTION_COUNT, ETH_GET_CODE, ETH_CALL, ETH_GET_BLOCK_BY_NUMBER, ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER, ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER, ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX. | latest | String | |
The hash of the block, for ETH_GET_BLOCK_BY_HASH, ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH, ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH, ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX. | String | ||
A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE. | String | ||
The data, as a hex string. For ETH_SEND_TRANSACTION, ETH_CALL, ETH_ESTIMATE_GAS and QUORUM_ETH_SEND_TRANSACTION, the data of the transaction: the compiled code of a contract to create, or the hash of the method signature and the encoded parameters of a contract call. For SHH_POST, the payload of the Whisper message. For SHH_NEW_FILTER, the Whisper identity that the messages are sent to. | String | ||
The name of the local database of the node, for the DB_PUT_STRING, DB_GET_STRING, DB_PUT_HEX and DB_GET_HEX operations. | String | ||
The id of the filter, as a decimal number, for ETH_UNINSTALL_FILTER, ETH_GET_FILTER_CHANGES, ETH_GET_FILTER_LOGS, SHH_UNINSTALL_FILTER, SHH_GET_FILTER_CHANGES and SHH_GET_MESSAGES. | BigInteger | ||
The price in wei of each unit of gas, for ETH_SEND_TRANSACTION and ETH_CALL. When not set, the node chooses it. | BigInteger | ||
The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes. | String | ||
The proof-of-work hash of the block header (256 bits), as a hex string, for ETH_SUBMIT_WORK. | String | ||
The index of the transaction or the uncle in the block, as a decimal number, for ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX, ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX, ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX and ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX. | BigInteger | ||
The key in the local database of the node, for the DB_PUT_STRING, DB_GET_STRING, DB_PUT_HEX and DB_GET_HEX operations. | String | ||
The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK. | String | ||
The nonce. For ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION, the nonce of the transaction as a decimal number; when not set, the node chooses it. For ETH_SUBMIT_WORK, the proof-of-work nonce found (64 bits), as a hex string. | String | ||
The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads, as a decimal number. | BigInteger | ||
The priority of the Whisper message that SHH_POST sends. | BigInteger | ||
The data that ETH_SIGN signs, as a hex string. The node signs it, with the Ethereum signed message prefix, with the key of the account in the address option. | String | ||
The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string: a message call or a contract creation. | String | ||
The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles. | String | ||
The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT. | String | ||
The time to live in seconds of the Whisper message that SHH_POST sends. | BigInteger | ||
The amount of wei that the transaction transfers, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION. | BigInteger | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The Web3j Ethereum Blockchain component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelWeb3jEthHashrate (producer) Constant: | The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes. Overrides the hashrate option. | String | |
| Constant: | The id of the JSON-RPC request. When not set, web3j chooses the id. | Long | |
CamelWeb3jOperation (producer) Constant: | The operation to perform, such as ETH_GET_BALANCE. Overrides the operation option. | String | |
| Constant: | The block that the operation reads the state at: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Overrides the atBlock option. | String | |
| Constant: | The address of the account or contract, or the Whisper identity for SHH_HAS_IDENTITY and SHH_ADD_TO_GROUP. Overrides the address option. | String | |
CamelWeb3jAddresses (producer) Constant: | The contract addresses whose logs ETH_NEW_FILTER and ETH_GET_LOGS filter on, as a List of String. The producer ignores a String value. | List | |
CamelWeb3jFromAddress (producer) Constant: | The address that the transaction is sent from, or the Whisper identity of the sender for SHH_POST. Overrides the fromAddress option. | String | |
CamelWeb3jToAddress (producer) Constant: | The address that the transaction is sent to, or the Whisper identity of the receiver for SHH_POST. Overrides the toAddress option. | String | |
| Constant: | The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads. Overrides the position option. | String | |
CamelWeb3jBlockHash (producer) Constant: | The hash of the block. Overrides the blockHash option. | String | |
CamelWeb3jTransactionHash (producer) Constant: | The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT. Overrides the transactionHash option. | String | |
CamelWeb3jSha3HashOfDataToSign (producer) Constant: | The data that ETH_SIGN signs, as a hex string. Overrides the sha3HashOfDataToSign option. | String | |
CamelWeb3jSignedTransactionData (producer) Constant: | The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string. Overrides the signedTransactionData option. | String | |
CamelWeb3jFullTransactionObjects (producer) Constant: | Whether a block holds the full transaction objects (true) or only the hashes of its transactions (false). Overrides the fullTransactionObjects option. | Boolean | |
| Constant: | The index of the transaction or the uncle in the block. Overrides the index option. | String | |
CamelWeb3jSourceCode (producer) Constant: | The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles. Overrides the sourceCode option. | String | |
| Constant: | The id of the filter. Overrides the filterId option. | BigInteger | |
CamelWeb3jDatabaseName (producer) Constant: | The name of the local database of the node, for the DB_* operations. Overrides the databaseName option. | String | |
| Constant: | The key in the local database of the node, for the DB_* operations. Overrides the keyName option. | String | |
| Constant: | The nonce of the transaction as a number, or for ETH_SUBMIT_WORK the proof-of-work nonce found as a hex string. Overrides the nonce option. | BigInteger | |
CamelWeb3jHeaderPowHash (producer) Constant: | The proof-of-work hash of the block header (256 bits), as a hex string, for ETH_SUBMIT_WORK. Overrides the headerPowHash option. | String | |
CamelWeb3jMixDigest (producer) Constant: | The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK. Overrides the mixDigest option. | String | |
| Constant: | A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE. Overrides the clientId option. | String | |
| Constant: | The price in wei of each unit of gas. Overrides the gasPrice option. | BigInteger | |
| Constant: | The maximum amount of gas that the transaction can use. Overrides the gasLimit option. | BigInteger | |
| Constant: | The amount of wei that the transaction transfers. Overrides the value option. | BigInteger | |
| Constant: | The data of the transaction, the payload of the Whisper message for SHH_POST, or the Whisper identity for SHH_NEW_FILTER, as a hex string. Overrides the data option. | String | |
CamelWeb3jFromBlock (producer) Constant: | The first block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Overrides the fromBlock option. | String | |
| Constant: | The last block of the range: a block number in decimal, or a block tag: earliest, latest, pending, safe, finalized or accepted. Overrides the toBlock option. | String | |
| Constant: | The topics, as a List of String: for ETH_NEW_FILTER, ETH_GET_LOGS and SHH_NEW_FILTER matched by position, where an empty entry matches any topic, and for SHH_POST the topics of the Whisper message. The producer ignores a String value. | List | |
| Constant: | The priority of the Whisper message that SHH_POST sends. Overrides the priority option. | BigInteger | |
| Constant: | The time to live in seconds of the Whisper message that SHH_POST sends. Overrides the ttl option. | BigInteger | |
CamelWeb3jPrivateFor (producer) Constant: | The public keys of the Quorum nodes that receive the private transaction that QUORUM_ETH_SEND_TRANSACTION sends, as a List of String. Overrides the privateFor option. | List | |
CamelWeb3jPrivateFrom (producer) Constant: | The public key of the Quorum node that sends the private transaction with QUORUM_ETH_SEND_TRANSACTION. | String | |
CamelWeb3jErrorCode (producer) Constant: | The code of the JSON-RPC error that the node returned. The exchange then fails. | int | |
CamelWeb3jErrorData (producer) Constant: | The data of the JSON-RPC error that the node returned. | String | |
CamelWeb3jErrorMessage (producer) Constant: | The message of the JSON-RPC error that the node returned. | String | |
| Constant: | Set to done on the message that the consumer sends when the subscription completes. | String | |
CamelWeb3jHeaderOperation (consumer) Constant: | The operation of the subscription that completed, on the message with the CamelWeb3jStatus header set to done. | String |
Message Body
The message body at each side of the Web3j Ethereum Blockchain component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| One message per item of the subscription of the operation: the hash of a block or a pending transaction as a String, an EthBlock.Block, a Transaction or a Log of web3j. No body on the message that ends the subscription (header CamelWeb3jStatus=done) or carries its error.
Not known when |
Producer input |
| The operations take their input from headers and options, except WEB3_SHA3, DB_PUT_STRING, DB_PUT_HEX and QUORUM_GET_PRIVATE_PAYLOAD, which send the body converted to a String: a Map or a POJO is sent as its toString. |
Producer output |
| The result of the JSON-RPC call of the operation, selected by the CamelWeb3jOperation header or the operation option: a String for a hash, an address or hex data, a BigInteger for a quantity, a Boolean, a List, or a web3j object such as an EthBlock.Block, a Transaction or a TransactionReceipt (null when not found). On a JSON-RPC error the body is unchanged and the exchange fails, with the CamelWeb3jErrorCode, CamelWeb3jErrorData and CamelWeb3jErrorMessage headers.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
All URI options can also be set as exchange headers.
Examples
Listen for new mined blocks and send the block hash to a jms queue:
-
Java
-
XML
-
YAML
from("web3j://http://127.0.0.1:7545?operation=ETH_BLOCK_HASH_OBSERVABLE")
.to("jms:queue:blocks"); <route>
<from uri="web3j://http://127.0.0.1:7545?operation=ETH_BLOCK_HASH_OBSERVABLE"/>
<to uri="jms:queue:blocks"/>
</route> - route:
from:
uri: "web3j://http://127.0.0.1:7545"
parameters:
operation: ETH_BLOCK_HASH_OBSERVABLE
steps:
- to:
uri: jms:queue:blocks Use the block hash code to retrieve the block and full transaction details:
-
Java
-
XML
-
YAML
from("jms:queue:blocks")
.setHeader(BLOCK_HASH, body())
.to("web3j://http://127.0.0.1:7545?operation=ETH_GET_BLOCK_BY_HASH&fullTransactionObjects=true"); <route>
<from uri="jms:queue:blocks"/>
<setHeader name="BLOCK_HASH">
<simple>${body}</simple>
</setHeader>
<to uri="web3j://http://127.0.0.1:7545?operation=ETH_GET_BLOCK_BY_HASH&fullTransactionObjects=true"/>
</route> - route:
from:
uri: jms:queue:blocks
steps:
- setHeader:
name: BLOCK_HASH
simple: "${body}"
- to:
uri: "web3j://http://127.0.0.1:7545"
parameters:
operation: ETH_GET_BLOCK_BY_HASH
fullTransactionObjects: true Read the balance of an address at a specific block number:
-
Java
-
XML
-
YAML
from("direct:start")
.to("web3j://http://127.0.0.1:7545?operation=ETH_GET_BALANCE&address=0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952&atBlock=10"); <route>
<from uri="direct:start"/>
<to uri="web3j://http://127.0.0.1:7545?operation=ETH_GET_BALANCE&address=0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952&atBlock=10"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: "web3j://http://127.0.0.1:7545"
parameters:
operation: ETH_GET_BALANCE
address: "0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952"
atBlock: 10 UndeliverableException when a filter is removed
The consumer operations ETH_LOG_OBSERVABLE, ETH_BLOCK_HASH_OBSERVABLE, ETH_PENDING_TRANSACTION_HASH_OBSERVABLE, BLOCK_OBSERVABLE, TRANSACTION_OBSERVABLE and PENDING_TRANSACTION_OBSERVABLE install a filter on the node and poll it. web3j removes the filter with eth_uninstallFilter when the consumer stops. For BLOCK_OBSERVABLE, TRANSACTION_OBSERVABLE and PENDING_TRANSACTION_OBSERVABLE, web3j also removes it when fetching a block or a transaction fails, before the consumer subscribes again.
If eth_uninstallFilter fails, for example because the node is down or has already dropped the filter, RxJava reports an io.reactivex.exceptions.UndeliverableException caused by web3j’s org.web3j.protocol.core.filters.FilterException. By default RxJava prints the stack trace and passes it to the uncaught exception handler of the thread. This is only noise: the consumer keeps working. The cause is in web3j, see web3j issue 1937.
To log these errors at a lower level, an application can set a JVM-wide RxJava 2 error handler once at startup, before the routes start. The handler below logs the web3j filter errors at DEBUG and handles all other errors as RxJava does by default:
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.plugins.RxJavaPlugins;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.protocol.core.filters.FilterException;
Logger LOG = LoggerFactory.getLogger("web3j-filters");
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException && e.getCause() instanceof FilterException) {
LOG.debug("web3j could not uninstall a filter: {}", e.getCause().getMessage());
return;
}
// what RxJava does when no error handler is set
e.printStackTrace();
Thread thread = Thread.currentThread();
thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
});