Skip to content

Web3j

Platform 6 web3j combined Consumer & Producer using the web3j client API allowing read/write from/to Geth/Parity compatible Ethereum nodes.

This is based on a clone of the component camel-web3j, which was in early beta when Platform 6 was first released.

URI Format

web3j://ethereumClientUrl[?options]

You can append query options to the URI in the following format:

?options=value&option2=value&...

Options

The P6 Web3j client for Ethereum blockchain component supports two options which are described below.

Name Description Default Type
configuration (common) Default configuration Web3jConfiguration
resolveProperty Placeholders (advanced) Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. true boolean

The P6 Web3j client for Ethereum blockchain endpoint is configured using URI syntax with the path and query parameters listed below:

web3j:host:port

Path parameters

Name Description Default Type
nodeAddress Required Sets the node address used to communicate String

Query parameters

Name Description Default Type
addresses (common) The 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 DefaultBlockParameter
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) Used for Quorum, indicates a list of nodes exchanging private transactions. List
privateFrom (common) Used for Quorum, public key of a node sending a private transaction. String
quorumAPI (common) True if interacting with Quorum, false otherwise. 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 DefaultBlockParameter
topics (common) Topics are order-dependent. Each topic can also be a list of topics. List
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 options 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. 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 DefaultBlockParameter
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 index position in the block. BigInteger
keyName (producer) The key name in the database. String
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 within 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

Notes on the List type

  • The List type is a series of strings delimited with the | (pipe) character.
  • The keyword null is a special placeholder useful when specifying topics List. See https://github.com/ethereum/wiki/wiki/JSON-RPC#a-note-on-specifying-topic-filters/
  • Any string encapsulated in #{} will be automatically expanded as the Keccak-256 SHA3 of the value.
  • Using a List of List is not possible and as such the logical OR operator when referring to topics is not supported.
  • When using the topics List, any values given that are not 32 BYTES will be auto extended to meet this format (i.e. left padded with zeros).

The P6 Web3j consumer is capable of subscribing to events streams of the following types:

  • ETH_LOG_FLOWABLE
  • ETH_BLOCK_HASH_FLOWABLE
  • ETH_PENDING_TRANSACTION_HASH_FLOWABLE
  • TRANSACTION_FLOWABLE
  • PENDING_TRANSACTION_FLOWABLE
  • BLOCK_FLOWABLE
  • REPLAY_PAST_BLOCKS_FLOWABLE
  • REPLAY_PAST_TRANSACTIONS_FLOWABLE
  • REPLAY_ALL_PAST_BLOCKS_FLOWABLE
  • REPLAY_ALL_PAST_TRANSACTIONS_FLOWABLE
  • REPLAY_PAST_AND_FUTURE_BLOCKS_FLOWABLE
  • REPLAY_PAST_AND_FUTURE_TRANSACTIONS_FLOWABLE

These all relate to the filters supported by web3j and documented here: https://docs.web3j.io/filters.html.

The P6 Web3j producer is capable of performing the following operations:

  • WEB3_CLIENT_VERSION
  • WEB3_SHA3
  • NET_VERSION
  • NET_LISTENING
  • NET_PEER_COUNT
  • ethProtocolVersion
  • ETH_COINBASE
  • ETH_SYNCING
  • ETH_MINING
  • ETH_HASHRATE
  • ETH_GAS_PRICE
  • ETH_ACCOUNTS
  • ETH_BLOCK_NUMBER
  • ETH_GET_BALANCE
  • ETH_GET_STORAGE_AT
  • ETH_GET_TRANSACTION_COUNT
  • ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH
  • ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER
  • ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH
  • ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER
  • ETH_GET_CODE
  • ETH_SIGN
  • ETH_SEND_TRANSACTION
  • ETH_SEND_RAW_TRANSACTION
  • ETH_CALL
  • ETH_ESTIMATE_GAS
  • ETH_GET_BLOCK_BY_HASH
  • ETH_GET_BLOCK_BY_NUMBER
  • ETH_GET_TRANSACTION_BY_HASH
  • ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX
  • ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX
  • ETH_GET_TRANSACTION_RECEIPT
  • ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX
  • ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX
  • ETH_GET_COMPILERS
  • ETH_COMPILE_LLL
  • ETH_COMPILE_SOLIDITY
  • ETH_COMPILE_SERPENT
  • ETH_NEW_FILTER
  • ETH_NEW_BLOCK_FILTER
  • ETH_NEW_PENDING_TRANSACTION_FILTER
  • ETH_UNINSTALL_FILTER
  • ETH_GET_FILTER_CHANGES
  • ETH_GET_FILTER_LOGS
  • ETH_GET_LOGS
  • ETH_GET_WORK
  • ETH_SUBMIT_WORK
  • ETH_SUBMIT_HASHRATE
  • DB_PUT_STRING
  • DB_GET_STRING
  • DB_PUT_HEX
  • DB_GET_HEX
  • SHH_VERSION
  • SHH_POST
  • SHH_NEW_IDENTITY
  • SHH_HAS_IDENTITY
  • SHH_NEW_GROUP
  • SHH_ADD_TO_GROUP
  • SHH_NEW_FILTER
  • SHH_UNINSTALL_FILTER
  • SHH_GET_FILTER_CHANGES
  • SHH_GET_MESSAGES

Each refers to a JSON-RPC API operation as defined here: https://github.com/ethereum/wiki/wiki/JSON-RPC#json-rpc-api-reference and called via the web3j implementation: https://github.com/web3j/web3j.

Example

Template: Dev_BaseRoute.groovy

${addRoutes} :=

def contractAddress = p6.configuration.getProperty("erc20.contract.address", "0x0A35dB94da8E787b1C10bC5d9A7761d151BEDeaF")
def toAddress = p6.configuration.getProperty("erc20.transferTo.address", "0xe26b50ae30945efac2b1dd8897a29c3efc1d9780")

from("web3j://http://127.0.0.1:8545?operation=ETH_LOG_FLOWABLE&address=" + contractAddress + "&topics=#{Transfer(address|address|uint256)},null," + toAddress)
    .filter {
        // Add additional filtering on Log* headers in here using groovy expressions if required
        // it.in.headers.logType for example
        true
    }
    .to("p6cmb://scripts?platform6.request.action=execute&id=TransferHandler") 
    .routeId("EthRoute")
    .description("Contract Transfer() to erc20.transferTo.address")

${destroyRoutes} :=

camel.destroyRoute("EthRoute")

In the receiving script, TransferHandler, the parameters from the log event can be decoded and used as follows:

def lstNoneIndexedValues = p6.ethereumrpc.decodeEventData( p6.pipeline.get("logData"), "uint256" )
println "Decoded log data: " + lstNoneIndexedValues

def lstIndexedValues = p6.ethereumrpc.decodeLogTopics( p6.pipeline.get("logTopics"), "address", "address" )
println "Decoded log topics: " + lstIndexedValues