[[web3j-component]]
= Web3j Ethereum Blockchain Component
:docTitle: Web3j Ethereum Blockchain
:artifactId: camel-web3j
:description: Interact with Ethereum nodes using web3j client API.
:since: 2.22
:supportLevel: Stable
:component-header: Both producer and consumer are supported
include::{cq-version}@camel-quarkus:ROOT:partial$reference/components/web3j.adoc[opts=optional]

*Since Camel {since}*

*{component-header}*

The Ethereum blockchain component uses the
https://github.com/web3j/web3j[web3j] client
API and allows you to interact with Ethereum compatible nodes such as https://github.com/ethereum/go-ethereum/wiki/geth[Geth], https://github.com/paritytech/parity[Parity], https://github.com/jpmorganchase/quorum/wiki[Quorum], https://infura.io[Infura], etc.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<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

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

== Web3j Options


// component options: START
The Web3j Ethereum Blockchain component supports 38 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *addresses* (common) | Contract address or a list of addresses. |  | List
| *configuration* (common) | Default configuration |  | Web3jConfiguration
| *fromAddress* (common) | The address the transaction is send from |  | String
| *fromBlock* (common) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *fullTransactionObjects* (common) | If true it returns the full transaction objects, if false only the hashes of the transactions. | false | boolean
| *gasLimit* (common) | The maximum gas allowed in this block. |  | BigInteger
| *privateFor* (common) | A transaction privateFor nodes with public keys in a Quorum network |  | List
| *quorumAPI* (common) | If true, this will support Quorum API. | false | boolean
| *toAddress* (common) | The address the transaction is directed to. |  | String
| *toBlock* (common) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *topics* (common) | Topics are order-dependent. Each topic can also be a list of topics. Specify multiple topics separated by comma. |  | String
| *web3j* (common) | The preconfigured Web3j object. |  | Web3j
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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) | Contract address. |  | String
| *atBlock* (producer) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *blockHash* (producer) | Hash of the block where this transaction was in. |  | String
| *clientId* (producer) | A random hexadecimal(32 bytes) ID identifying the client. |  | String
| *data* (producer) | The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. |  | String
| *databaseName* (producer) | The local database name. |  | String
| *filterId* (producer) | The filter id to use. |  | BigInteger
| *gasPrice* (producer) | Gas price used for each paid gas. |  | BigInteger
| *hashrate* (producer) | A hexadecimal string representation (32 bytes) of the hash rate. |  | String
| *headerPowHash* (producer) | The header's pow-hash (256 bits) used for submitting a proof-of-work solution. |  | String
| *index* (producer) | The transactions/uncle index position in the block. |  | BigInteger
| *keyName* (producer) | The key name in the database. |  | 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) used for submitting a proof-of-work solution. |  | String
| *nonce* (producer) | The nonce found (64 bits) used for submitting a proof-of-work solution. |  | String
| *operation* (producer) | Operation to use. | transaction | String
| *position* (producer) | The transaction index position withing a block. |  | BigInteger
| *priority* (producer) | The priority of a whisper message. |  | BigInteger
| *sha3HashOfDataToSign* (producer) | Message to sign by calculating an Ethereum specific signature. |  | String
| *signedTransactionData* (producer) | The signed transaction data for a new message call transaction or a contract creation for signed transactions. |  | String
| *sourceCode* (producer) | The source code to compile. |  | String
| *transactionHash* (producer) | The information about a transaction requested by transaction hash. |  | String
| *ttl* (producer) | The time to live in seconds of a whisper message. |  | BigInteger
| *value* (producer) | The value sent within a 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
|===
// component options: END


// endpoint options: START
The Web3j Ethereum Blockchain endpoint is configured using URI syntax:

----
web3j:nodeAddress
----

with the following path and query parameters:

=== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *nodeAddress* | *Required* Sets the node address used to communicate |  | String
|===


=== Query Parameters (39 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *addresses* (common) | Contract address or a list of addresses. |  | List
| *fromAddress* (common) | The address the transaction is send from |  | String
| *fromBlock* (common) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *fullTransactionObjects* (common) | If true it returns the full transaction objects, if false only the hashes of the transactions. | false | boolean
| *gasLimit* (common) | The maximum gas allowed in this block. |  | BigInteger
| *privateFor* (common) | A transaction privateFor nodes with public keys in a Quorum network |  | List
| *quorumAPI* (common) | If true, this will support Quorum API. | false | boolean
| *toAddress* (common) | The address the transaction is directed to. |  | String
| *toBlock* (common) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *topics* (common) | Topics are order-dependent. Each topic can also be a list of topics. Specify multiple topics separated by comma. |  | String
| *web3j* (common) | The preconfigured Web3j object. |  | Web3j
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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) | 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) | Sets the exchange pattern when the consumer creates an exchange. There are 3 enums and the value can be one of: InOnly, InOut, InOptionalOut |  | ExchangePattern
| *address* (producer) | Contract address. |  | String
| *atBlock* (producer) | The block number, or the string latest for the last mined block or pending, earliest for not yet mined transactions. | latest | String
| *blockHash* (producer) | Hash of the block where this transaction was in. |  | String
| *clientId* (producer) | A random hexadecimal(32 bytes) ID identifying the client. |  | String
| *data* (producer) | The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. |  | String
| *databaseName* (producer) | The local database name. |  | String
| *filterId* (producer) | The filter id to use. |  | BigInteger
| *gasPrice* (producer) | Gas price used for each paid gas. |  | BigInteger
| *hashrate* (producer) | A hexadecimal string representation (32 bytes) of the hash rate. |  | String
| *headerPowHash* (producer) | The header's pow-hash (256 bits) used for submitting a proof-of-work solution. |  | String
| *index* (producer) | The transactions/uncle index position in the block. |  | BigInteger
| *keyName* (producer) | The key name in the database. |  | 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) used for submitting a proof-of-work solution. |  | String
| *nonce* (producer) | The nonce found (64 bits) used for submitting a proof-of-work solution. |  | String
| *operation* (producer) | Operation to use. | transaction | String
| *position* (producer) | The transaction index position withing a block. |  | BigInteger
| *priority* (producer) | The priority of a whisper message. |  | BigInteger
| *sha3HashOfDataToSign* (producer) | Message to sign by calculating an Ethereum specific signature. |  | String
| *signedTransactionData* (producer) | The signed transaction data for a new message call transaction or a contract creation for signed transactions. |  | String
| *sourceCode* (producer) | The source code to compile. |  | String
| *transactionHash* (producer) | The information about a transaction requested by transaction hash. |  | String
| *ttl* (producer) | The time to live in seconds of a whisper message. |  | BigInteger
| *value* (producer) | The value sent within a transaction. |  | BigInteger
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
|===
// endpoint options: END



You can append query options to the URI in the following format,
?options=value&option2=value&...


== Message Headers

[width="100%",cols="10%,90%",options="header",]
|=======================================================================
|Header |Description

|`All URI options` |All URI options can also be set as exchange headers.

|=======================================================================



== Samples

Listen for new mined blocks and send the block hash to a jms queue:

[source,java]
---------------------------------------------------------------------------------------------
from("web3j://http://127.0.0.1:7545?operation=ETH_BLOCK_HASH_OBSERVABLE")
    .to("jms:queue:blocks");
---------------------------------------------------------------------------------------------

Use the block hash code to retrieve the block and full transaction details:

[source,java]
---------------------------------------------------------
from("jms:queue:blocks")
    .setHeader(BLOCK_HASH, body())
    .to("web3j://http://127.0.0.1:7545?operation=ETH_GET_BLOCK_BY_HASH&fullTransactionObjects=true");
---------------------------------------------------------

Read the balance of an address at a specific block number:

[source,java]
--------------------------------------------------------
from("direct:start")
    .to("web3j://http://127.0.0.1:7545?operation=ETH_GET_BALANCE&address=0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952&atBlock=10");
--------------------------------------------------------

include::camel-spring-boot::page$web3j-starter.adoc[]
