hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.11k stars 1.69k forks source link

Doesn't work with Corda Flow #1167

Closed shun-tak closed 4 years ago

shun-tak commented 4 years ago

_Issuetitle

Run web3.ethSendTransaction(tx).send doesn't work in Corda

_Issuedescription

I tried to run web3j to send tx to Ethereum from Corda. However, it returned error like this

[INFO ] 2020-02-28T07:49:59,338Z [Node thread-1] corda.flow.run - Flow raised an error... sending it to flow hospital {actor_id=internalShell, actor_owning_identity=O=ParticipantA, L=London, C=GB, actor_store_id=NODE_CONFIG, fiber-id=10000001, flow-id=76edee53-897f-48ac-b1b1-776571a74313, invocation_id=3b6bc56b-9bee-4a78-b05a-46d18f3f08e4, invocation_timestamp=2020-02-28T07:49:59.025Z, origin=internalShell, session_id=128fc04e-ca5f-4980-9317-1753046cf745, session_timestamp=2020-02-28T07:49:58.807Z, thread-id=138}
java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
    at org.web3j.protocol.http.HttpService.performIO(HttpService.java:154) ~[core-4.5.15.jar:?]
    at org.web3j.protocol.Service.send(Service.java:48) ~[core-4.5.15.jar:?]
    at org.web3j.protocol.core.Request.send(Request.java:87) ~[core-4.5.15.jar:?]
    at jp.co.layerx.cordage.flowethereumtx.Flow.call(Flow.kt:32) ~[?:?]
    at jp.co.layerx.cordage.flowethereumtx.Flow.call(Flow.kt:17) ~[?:?]

It seems okhttp3.RequestBody.create doesn't exist but I surely resolved dependencies. If it was not resolved, it should have returned NoSuchMethodError for web3j (this is confirmed).

I'm not sure but around Kotlin extension function may be a cause.

https://github.com/square/okhttp/blob/parent-4.3.1/okhttp/src/main/java/okhttp3/RequestBody.kt#L167-L175 https://github.com/web3j/web3j/blob/v4.5.15/core/src/main/java/org/web3j/protocol/http/HttpService.java#L154

_Issuecontext

I would be grateful if someone commented on this.

antonydenyer commented 4 years ago

We upgraded the version of okhttp in https://github.com/web3j/web3j/releases/tag/v4.5.12 you can either use a version prior to this as it is using okhttp v3.8.1 which should be compatible with the okhttp version v3.5.0 which is what corda v4 pulls in.

shun-tak commented 4 years ago

web3j 4.5.11 worked very well with Corda Flow! Thank you for your great information!