Camel Components

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>

URI Format

web3j://<local/remote host:port or local IPC path>[?options]

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, *.yaml files, 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

addresses (common)

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

configuration (common)

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

fromAddress (common)

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

fromBlock (common)

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

fullTransactionObjects (common)

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

gasLimit (common)

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 (common)

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

privateFor (common)

A comma separated list of the public keys of the Quorum nodes that receive the private transaction that QUORUM_ETH_SEND_TRANSACTION sends.

String

quorumAPI (common)

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

toAddress (common)

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

toBlock (common)

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

topics (common)

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

web3j (common)

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

bridgeErrorHandler (consumer)

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

address (producer)

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

atBlock (producer)

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

blockHash (producer)

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

clientId (producer)

A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE.

String

data (producer)

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

databaseName (producer)

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

filterId (producer)

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

gasPrice (producer)

The price in wei of each unit of gas, for ETH_SEND_TRANSACTION and ETH_CALL. When not set, the node chooses it.

BigInteger

hashrate (producer)

The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes.

String

headerPowHash (producer)

The proof-of-work hash of the block header (256 bits), as a hex string, for ETH_SUBMIT_WORK.

String

index (producer)

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

keyName (producer)

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

lazyStartProducer (producer)

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

mixDigest (producer)

The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK.

String

nonce (producer)

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

position (producer)

The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads, as a decimal number.

BigInteger

priority (producer)

The priority of the Whisper message that SHH_POST sends.

BigInteger

sha3HashOfDataToSign (producer)

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

signedTransactionData (producer)

The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string: a message call or a contract creation.

String

sourceCode (producer)

The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles.

String

transactionHash (producer)

The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT.

String

ttl (producer)

The time to live in seconds of the Whisper message that SHH_POST sends.

BigInteger

value (producer)

The amount of wei that the transaction transfers, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION.

BigInteger

autowiredEnabled (advanced)

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:

Path Parameters

Name Description Default Type

nodeAddress (common)

Required The address of the Ethereum node: the URL of its JSON-RPC endpoint when it starts with http, otherwise the path of its IPC socket (a named pipe on Windows). Not used when the web3j option is set.

String

Query Parameters

Name Description Default Type

addresses (common)

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

fromAddress (common)

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

fromBlock (common)

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

fullTransactionObjects (common)

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

gasLimit (common)

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 (common)

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

privateFor (common)

A comma separated list of the public keys of the Quorum nodes that receive the private transaction that QUORUM_ETH_SEND_TRANSACTION sends.

String

quorumAPI (common)

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

toAddress (common)

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

toBlock (common)

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

topics (common)

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

web3j (common)

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

bridgeErrorHandler (consumer (advanced))

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

exceptionHandler (consumer (advanced))

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

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

address (producer)

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

atBlock (producer)

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

blockHash (producer)

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

clientId (producer)

A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE.

String

data (producer)

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

databaseName (producer)

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

filterId (producer)

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

gasPrice (producer)

The price in wei of each unit of gas, for ETH_SEND_TRANSACTION and ETH_CALL. When not set, the node chooses it.

BigInteger

hashrate (producer)

The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes.

String

headerPowHash (producer)

The proof-of-work hash of the block header (256 bits), as a hex string, for ETH_SUBMIT_WORK.

String

index (producer)

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

keyName (producer)

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

mixDigest (producer)

The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK.

String

nonce (producer)

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

position (producer)

The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads, as a decimal number.

BigInteger

priority (producer)

The priority of the Whisper message that SHH_POST sends.

BigInteger

sha3HashOfDataToSign (producer)

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

signedTransactionData (producer)

The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string: a message call or a contract creation.

String

sourceCode (producer)

The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles.

String

transactionHash (producer)

The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT.

String

ttl (producer)

The time to live in seconds of the Whisper message that SHH_POST sends.

BigInteger

value (producer)

The amount of wei that the transaction transfers, for ETH_SEND_TRANSACTION, ETH_CALL and QUORUM_ETH_SEND_TRANSACTION.

BigInteger

lazyStartProducer (producer (advanced))

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: ETH_HASHRATE

The hash rate that ETH_SUBMIT_HASHRATE reports, as a hex string of 32 bytes. Overrides the hashrate option.

String

CamelWeb3jId (producer)

Constant: ID

The id of the JSON-RPC request. When not set, web3j chooses the id.

Long

CamelWeb3jOperation (producer)

Constant: OPERATION

The operation to perform, such as ETH_GET_BALANCE. Overrides the operation option.

String

CamelWeb3jAtBlock (producer)

Constant: AT_BLOCK

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

CamelWeb3jAddress (producer)

Constant: ADDRESS

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: ADDRESSES

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: FROM_ADDRESS

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: TO_ADDRESS

The address that the transaction is sent to, or the Whisper identity of the receiver for SHH_POST. Overrides the toAddress option.

String

CamelWeb3jPosition (producer)

Constant: POSITION

The position (slot) in the storage of the contract that ETH_GET_STORAGE_AT reads. Overrides the position option.

String

CamelWeb3jBlockHash (producer)

Constant: BLOCK_HASH

The hash of the block. Overrides the blockHash option.

String

CamelWeb3jTransactionHash (producer)

Constant: TRANSACTION_HASH

The hash of the transaction, for ETH_GET_TRANSACTION_BY_HASH and ETH_GET_TRANSACTION_RECEIPT. Overrides the transactionHash option.

String

CamelWeb3jSha3HashOfDataToSign (producer)

Constant: SHA3_HASH_OF_DATA_TO_SIGN

The data that ETH_SIGN signs, as a hex string. Overrides the sha3HashOfDataToSign option.

String

CamelWeb3jSignedTransactionData (producer)

Constant: SIGNED_TRANSACTION_DATA

The signed transaction that ETH_SEND_RAW_TRANSACTION sends, RLP encoded as a hex string. Overrides the signedTransactionData option.

String

CamelWeb3jFullTransactionObjects (producer)

Constant: FULL_TRANSACTION_OBJECTS

Whether a block holds the full transaction objects (true) or only the hashes of its transactions (false). Overrides the fullTransactionObjects option.

Boolean

CamelWeb3jIndex (producer)

Constant: INDEX

The index of the transaction or the uncle in the block. Overrides the index option.

String

CamelWeb3jSourceCode (producer)

Constant: SOURCE_CODE

The source code that ETH_COMPILE_LLL, ETH_COMPILE_SOLIDITY or ETH_COMPILE_SERPENT compiles. Overrides the sourceCode option.

String

CamelWeb3jFilterId (producer)

Constant: FILTER_ID

The id of the filter. Overrides the filterId option.

BigInteger

CamelWeb3jDatabaseName (producer)

Constant: DATABASE_NAME

The name of the local database of the node, for the DB_* operations. Overrides the databaseName option.

String

CamelWeb3jKeyName (producer)

Constant: KEY_NAME

The key in the local database of the node, for the DB_* operations. Overrides the keyName option.

String

CamelWeb3jNonce (producer)

Constant: NONCE

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: HEADER_POW_HASH

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: MIX_DIGEST

The mix digest (256 bits), as a hex string, for ETH_SUBMIT_WORK. Overrides the mixDigest option.

String

CamelWeb3jClientId (producer)

Constant: CLIENT_ID

A random id of 32 bytes, as a hex string, that identifies the client in ETH_SUBMIT_HASHRATE. Overrides the clientId option.

String

CamelWeb3jGasPrice (producer)

Constant: GAS_PRICE

The price in wei of each unit of gas. Overrides the gasPrice option.

BigInteger

CamelWeb3jGasLimit (producer)

Constant: GAS_LIMIT

The maximum amount of gas that the transaction can use. Overrides the gasLimit option.

BigInteger

CamelWeb3jValue (producer)

Constant: VALUE

The amount of wei that the transaction transfers. Overrides the value option.

BigInteger

CamelWeb3jData (producer)

Constant: DATA

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: FROM_BLOCK

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

CamelWeb3jToBlock (producer)

Constant: TO_BLOCK

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

CamelWeb3jTopics (producer)

Constant: TOPICS

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

CamelWeb3jPriority (producer)

Constant: PRIORITY

The priority of the Whisper message that SHH_POST sends. Overrides the priority option.

BigInteger

CamelWeb3jTtl (producer)

Constant: TTL

The time to live in seconds of the Whisper message that SHH_POST sends. Overrides the ttl option.

BigInteger

CamelWeb3jPrivateFor (producer)

Constant: PRIVATE_FOR

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: PRIVATE_FROM

The public key of the Quorum node that sends the private transaction with QUORUM_ETH_SEND_TRANSACTION.

String

CamelWeb3jErrorCode (producer)

Constant: ERROR_CODE

The code of the JSON-RPC error that the node returned. The exchange then fails.

int

CamelWeb3jErrorData (producer)

Constant: ERROR_DATA

The data of the JSON-RPC error that the node returned.

String

CamelWeb3jErrorMessage (producer)

Constant: ERROR_MESSAGE

The message of the JSON-RPC error that the node returned.

String

CamelWeb3jStatus (consumer)

Constant: HEADER_STATUS

Set to done on the message that the consumer sends when the subscription completes.

String

CamelWeb3jHeaderOperation (consumer)

Constant: HEADER_OPERATION

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

text, pojo or null

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.

  • With operation=ETH_BLOCK_HASH_OBSERVABLE: text or null (java.lang.String)

  • With operation=ETH_PENDING_TRANSACTION_HASH_OBSERVABLE: text or null (java.lang.String)

  • With operation=BLOCK_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=REPLAY_BLOCKS_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=TRANSACTION_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=PENDING_TRANSACTION_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=REPLAY_TRANSACTIONS_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=ETH_LOG_OBSERVABLE: pojo or null (org.web3j.protocol.core.methods.response.Log)

Not known when operation is set.

Producer input

any

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

unchanged

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.

  • With operation=WEB3_CLIENT_VERSION: text (java.lang.String)

  • With operation=WEB3_SHA3: text (java.lang.String)

  • With operation=NET_VERSION: text (java.lang.String)

  • With operation=ETH_PROTOCOL_VERSION: text (java.lang.String)

  • With operation=ETH_COINBASE: text (java.lang.String)

  • With operation=ETH_GET_STORAGE_AT: text (java.lang.String)

  • With operation=ETH_GET_CODE: text (java.lang.String)

  • With operation=ETH_SIGN: text (java.lang.String)

  • With operation=ETH_SEND_TRANSACTION: text (java.lang.String)

  • With operation=ETH_SEND_RAW_TRANSACTION: text (java.lang.String)

  • With operation=ETH_CALL: text (java.lang.String)

  • With operation=ETH_COMPILE_LLL: text (java.lang.String)

  • With operation=ETH_COMPILE_SERPENT: text (java.lang.String)

  • With operation=DB_GET_STRING: text (java.lang.String)

  • With operation=DB_GET_HEX: text (java.lang.String)

  • With operation=SHH_VERSION: text (java.lang.String)

  • With operation=SHH_NEW_IDENTITY: text (java.lang.String)

  • With operation=SHH_NEW_GROUP: text (java.lang.String)

  • With operation=QUORUM_ETH_SEND_TRANSACTION: text (java.lang.String)

  • With operation=QUORUM_GET_PRIVATE_PAYLOAD: text (java.lang.String)

  • With operation=NET_PEER_COUNT: value (java.math.BigInteger)

  • With operation=ETH_HASHRATE: value (java.math.BigInteger)

  • With operation=ETH_GAS_PRICE: value (java.math.BigInteger)

  • With operation=ETH_BLOCK_NUMBER: value (java.math.BigInteger)

  • With operation=ETH_GET_BALANCE: value (java.math.BigInteger)

  • With operation=ETH_GET_TRANSACTION_COUNT: value (java.math.BigInteger)

  • With operation=ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH: value (java.math.BigInteger)

  • With operation=ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER: value (java.math.BigInteger)

  • With operation=ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH: value (java.math.BigInteger)

  • With operation=ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER: value (java.math.BigInteger)

  • With operation=ETH_ESTIMATE_GAS: value (java.math.BigInteger)

  • With operation=ETH_NEW_FILTER: value (java.math.BigInteger)

  • With operation=ETH_NEW_BLOCK_FILTER: value (java.math.BigInteger)

  • With operation=ETH_NEW_PENDING_TRANSACTION_FILTER: value (java.math.BigInteger)

  • With operation=SHH_NEW_FILTER: value (java.math.BigInteger)

  • With operation=NET_LISTENING: value (java.lang.Boolean)

  • With operation=ETH_SYNCING: value (java.lang.Boolean)

  • With operation=ETH_MINING: value (java.lang.Boolean)

  • With operation=ETH_UNINSTALL_FILTER: value (java.lang.Boolean)

  • With operation=ETH_SUBMIT_WORK: value (java.lang.Boolean)

  • With operation=ETH_SUBMIT_HASHRATE: value (java.lang.Boolean)

  • With operation=DB_PUT_STRING: value (java.lang.Boolean)

  • With operation=DB_PUT_HEX: value (java.lang.Boolean)

  • With operation=SHH_POST: value (java.lang.Boolean)

  • With operation=SHH_HAS_IDENTITY: value (java.lang.Boolean)

  • With operation=SHH_ADD_TO_GROUP: value (java.lang.Boolean)

  • With operation=SHH_UNINSTALL_FILTER: value (java.lang.Boolean)

  • With operation=ETH_ACCOUNTS: list (java.util.List<java.lang.String>)

  • With operation=ETH_GET_COMPILERS: list (java.util.List<java.lang.String>)

  • With operation=ETH_GET_WORK: list (java.util.List<java.lang.String>)

  • With operation=ETH_GET_FILTER_CHANGES: list (java.util.List<org.web3j.protocol.core.methods.response.EthLog.LogResult<?>>)

  • With operation=ETH_GET_FILTER_LOGS: list (java.util.List<org.web3j.protocol.core.methods.response.EthLog.LogResult<?>>)

  • With operation=ETH_GET_LOGS: list (java.util.List<org.web3j.protocol.core.methods.response.EthLog.LogResult<?>>)

  • With operation=SHH_GET_FILTER_CHANGES: list (java.util.List<org.web3j.protocol.core.methods.response.ShhMessages.SshMessage>)

  • With operation=SHH_GET_MESSAGES: list (java.util.List<org.web3j.protocol.core.methods.response.ShhMessages.SshMessage>)

  • With operation=ETH_COMPILE_SOLIDITY: map (java.util.Map<java.lang.String, org.web3j.protocol.core.methods.response.EthCompileSolidity.Code>)

  • With operation=ETH_GET_BLOCK_BY_HASH: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=ETH_GET_BLOCK_BY_NUMBER: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX: pojo or null (org.web3j.protocol.core.methods.response.EthBlock.Block)

  • With operation=ETH_GET_TRANSACTION_BY_HASH: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX: pojo or null (org.web3j.protocol.core.methods.response.Transaction)

  • With operation=ETH_GET_TRANSACTION_RECEIPT: pojo or null (org.web3j.protocol.core.methods.response.TransactionReceipt)

  • With operation=QUORUM_NODE_INFO: pojo (org.web3j.protocol.core.methods.response.admin.AdminNodeInfo.NodeInfo)

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&amp;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&amp;address=0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952&amp;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);
});