Skip to content

Web3j

Platform 6 is bundled with Camel 3 web3j combined Consumer & Producer using the web3j client API allowing read/write from/to Hyperledger Besu, Geth or Parity compatible Ethereum nodes.

See: https://camel.apache.org/components/3.16.x/web3j-component.html for details

Examples

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} :=

p6.camel.destroyRoute("EthRoute")

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

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

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