Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:12
    1172510217 commented #1162
  • 02:12
    1172510217 commented #1162
  • Feb 20 18:31
    josh-richardson closed #1158
  • Feb 20 18:31
    josh-richardson closed #1158
  • Feb 20 09:40
    Mingela starred web3j/web3j
  • Feb 20 05:10
    01jiagnwei01 edited #1162
  • Feb 20 05:10
    01jiagnwei01 edited #1162
  • Feb 20 05:09
    01jiagnwei01 labeled #1162
  • Feb 20 05:09
    01jiagnwei01 labeled #1162
  • Feb 20 05:09
    01jiagnwei01 opened #1162
  • Feb 20 05:09
    01jiagnwei01 opened #1162
  • Feb 20 02:59
    1172510217 commented #1158
  • Feb 20 02:59
    1172510217 commented #1158
  • Feb 19 17:08
    fatimaleal opened #1161
  • Feb 19 17:08
    fatimaleal opened #1161
  • Feb 19 16:43
    josh-richardson commented #1158
  • Feb 19 16:43
    josh-richardson commented #1158
  • Feb 19 14:22
    stale[bot] labeled #1147
  • Feb 19 14:22
    stale[bot] labeled #1147
  • Feb 19 14:22
    stale[bot] commented #1147
Vladislav Dmitriev
@vladislavdmitriev
Hello everyone! I have a question regarding web3j. Do you know how can I know public and private key from existing ethereum wallet (I created it for testnet)? Web3j requires to set public and private key to perform transaction that changes blockchain state. Thank you.
Vladislav Dmitriev
@vladislavdmitriev
The main problem is that I receive exception "java.lang.RuntimeException: Could not construct a recoverable key. This should never happen." when I try to execute method of my smart contract wrapper (method changes blockchain state).
Conor Svensson
@conor10
@danieldietrich if the gas used by the transaction deployment = gas limit, this would imply one of two things:
  1. The gas limit isn’t high enough for the smart contract
  2. There’s an error in the smart contract itself causing the gas to be used up
    Given you said that it worked using the JavaScript deployment, please can you confirm the gas limit that was used when it was deployed successfully?
@vladislavdmitriev you can use WalletUtils to load the Ethereum wallet file https://docs.web3j.io/transactions.html#creating-and-working-with-wallet-files
parvfoss
@parvfoss
how can I sign and verify signature in web3j?how would public and private key play role?
Conor Svensson
@conor10
what's your specific use case? web3j performs the signing for you behind the scenes
Daniel Dietrich
@danieldietrich

@conor10

We deployed the same contract using web3.js to the same (private) geth node.

g$ geth version
Geth
Version: 1.5.9-stable
Git Commit: a07539fb88db7231d18db918ed7a6a4e32f97450
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.7.3
OS: linux
GOPATH=
GOROOT=/usr/lib/go-1.7

This is the transaction receipt:

{
    "blockHash": "0xf2d36a31d5fa687615b5df6cde1a4b56c692d07b8ce302d6055cf353add07532",
    "blockNumber": 50017,
    "contractAddress": "0x0509792e0ed7e8e23f3d34b458a266a85512186f",
    "cumulativeGasUsed": 1048006,
    "from": "0xd16336a9f47074ca5fb539b972f7e4451f25a997",
    "gasUsed": 1048006,
    "logs": [],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "root": "0x0dd342b1f9c7b3e7cacc97de56068545fd7a9c4e7156269117cd654c7661ff01",
    "to": null,
    "transactionHash": "0xd486ecbf1139a841c4043c2a616af382afe00976034cd6210a1f7d62edcdb32b",
    "transactionIndex": 0
}
library gas used
web3.js 1048006
web3j 4300000

However, there is still one difference between our two scenarios, Java and Javascript:

  • For Javascript we compile the contracts using the node module solc.js version 0.4.9
  • For Java we compile the contracts using the binary for Mac OS: /usr/local/bin/solc version 0.4.9+commit.364da425.Darwin.appleclang
Conor Svensson
@conor10
when you send the deploy transaction, can you check that the constructor arguments you send to the contract (if any) are encoded the same in both the JS & Java requests
You can try swapping out the OS X Solidity bytecode (from the ABI file) with the compiled JS Solidity bytecode in the smart contract wrapper file - that will help identify if the issue lies in Solidity versions or web3j
Daniel Dietrich
@danieldietrich

yep - I also prepared that suggestion this moment :) ------->

There is no constructor present, only one private contract variable:

mapping(address => OtherContract[]) private otherContracts;

I compared the ABI and BIN data generated by solc.js and the binary solc distribution (with and without the --optimize flag). The ABIs are the same, the BINs differ.

I will now generate the wrappers based on the BINs created by solc.js and look what happens when deploying them with Java...

Need to move to office - will come back....
parvfoss
@parvfoss
how can i sign transcation and retrieve it?
Daniel Dietrich
@danieldietrich

@conor10

When deploying the contract using the abi/bin created with solc.js I get the same result:

  • The server logs say that the contract is deployed and I receive the address
  • The transaction receipt shows a way too high gas-used: 4300000

My Javascript code is test code. I do not sign the transaction and I unlocked the account on the server side.

function deploy(contract, user) {
  web3.eth.contract(contract.abi).new({
    data: contract.binary,
    from: user,
    gas: TX_COST_LIMIT // = "3141592"
  }, (error, contractInstance) => /* handler code */)
}

For the Java code I copied the wallet from the server side to the client side because the contract wrappers need credentials.


Next step: Now I will create a raw transaction with Java
Daniel Dietrich
@danieldietrich

I created a Transaction with Java to deploy the contract (using the Javascript Binary):

String from = "0x<my-user>";
EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
        from, DefaultBlockParameterName.LATEST).send();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();
String BINARY = "0x<my-binary>";

Transaction transaction = Transaction.createContractTransaction(
        from,
        nonce,
        gasPrice,
        gasLimit,
        gasValue,
        BINARY);

EthSendTransaction transactionResponse =
        web3j.ethSendTransaction(transaction).send();

String transactionHash = transactionResponse.getTransactionHash();
`

Same result. Transaction receipt:

{
    "blockHash": "0x1156e969c888585cc11269c5d5d3cbef79bb719afddaa669a3ca31cb7b9ec5b1",
    "blockNumber": 51089,
    "contractAddress": "0x5df2c361206dc35ae03fc8049bbe1340e28a7948",
    "cumulativeGasUsed": 4300000,
    "from": "0xd16336a9f47074ca5fb539b972f7e4451f25a997",
    "gasUsed": 4300000,
    "logs": [],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "root": "0xfcbd82026383e04e2bd5a062b8ff03c42b637ae37a01d2a0a6ea096ba37087ef",
    "to": null,
    "transactionHash": "0x86d96471ceb7eb7059e04376a1bdd8ddda86addf399a9b0796a3d045309c8912",
    "transactionIndex": 0
}

I could now go s step backwards and create a simpler contract.

But the question remains: Why behave web3j and web3js different.

I could also change the contract and variable names and publish them (in a private gist?) for further investigation.

/cc @conor10
Conor Svensson
@conor10
@danieldietrich please do create a private Gist. You can work around this issue by using web3j's ClientTransactionManager instead of RawTransactionManager, but I'd like to get the the bottom of the issue. There was an RLP encoding fix (used by raw transactions) that went out with the 2.0 release which I presume you're already using
Conor Svensson
@conor10
@parvfoss please can you provide more specific details on what you’re trying to do
Me7e0r232
@Me7e0r232_twitter
Hey is there someone who has some experience with web3j shh/whisper? Has someone maybe an example code/link on how to receive shh messages in Java? Cause It looks like I'm able to send shh messages, but I can't receive them.
Conor Svensson
@conor10
It works in a similar manner to filters - you’ll need to create a whisper filter to receive messages
then poll periodically for responses
Song
@wbinSong
someone know how to querying the state of a smart contract using web3j in Android?
Web3j web3j = Web3jFactory.build(new HttpService(url));
                    List<Type> inputParameters = new ArrayList<>();
                    List<TypeReference<?>> outputParameters = new ArrayList<>();
                    Function function = new Function("getManufacturer",
                            inputParameters,
                            outputParameters);
                    String functionEncoder = FunctionEncoder.encode(function);
                    EthCall response = web3j.ethCall(
                            Transaction.createEthCallTransaction(contractAddress, functionEncoder),
                            DefaultBlockParameterName.LATEST
                    ).sendAsync().get();
                    List<Type> someType = FunctionReturnDecoder.decode(response.getValue(), function.getOutputParameters());
                    Type resault = someType.get(0);
                    String a = resault.toString();
                    Log.d("MainActitity", a + "111");
but the Type resault size is 0. someone know what's wrong?
i copy this function Querying the state of a smart contract
Conor Svensson
@conor10
@wbinSong it's easier to use the web3j smart contract wrappers to work with smart contracts, see https://docs.web3j.io/smart_contracts.html#solidity-smart-contract-wrappers
regarding your query you need to ensure that the inputParameters & outputParameter types match those of the smart contract method that you're trying to call
Dmitriy Startsev
@dstarcev
Is web3j supposed to be thread-safe?
Samuel Brooks
@industrialist
@dstarcev why do you ask?
Conor Svensson
@conor10
@dstarcev web3j is not stateful. What's your use case? If you're looking at high throughput with the library, I've had some discussions with @ferOnti about this. This PR provides some background on his work web3j/web3j#56
Dmitriy Startsev
@dstarcev
@conor10 @ramboze It was chrashing when I tried to send transactions concurrently. Maybe there is a race condition when you get the last nonce and use it to send a transaction
But this nonce may have already been used. I realize this is impossible to solve at library level, because nonce may be changed from another place, which is out of control.
Dmitriy Startsev
@dstarcev
Thus we have to handle such errors at application level anyway. I am not sure if this case should be covered by the library
Conor Svensson
@conor10
@dstarcev I created the following transaction manager for supporting higher transaction throughput (https://github.com/web3j/web3j/blob/master/src/main/java/org/web3j/tx/FastRawTransactionManager.java) and @ferOnti has played around with his own too. What's the crashing that you're seeing?
Dmitriy Startsev
@dstarcev
Transaction with the same hash was already imported.
this is because I send transactions that are the same. Only the nonce is different
Conor Svensson
@conor10
ah fine, so it's an error with sending multiple transactions per block. I'd recommend either you take a look at the FastRawTransactionManager, or if you want to use the normal transaction manager, it would be worthwhile contributing to the following discussion web3j/web3j#54 - currently its not been clarified if this could provide a solution to sending multiple transactions
Dmitriy Startsev
@dstarcev
thanks
Conor Svensson
@conor10
np
Dmitriy Startsev
@dstarcev
Is it planned to support structs in contract wrappers?
a simple DTO instead of List<Type>
POJO I mean
or is it not present in abi?
Ok, I see the name of a struct is not present, but we still can return something more typed
Conor Svensson
@conor10
If we weren't to use a collection of Type, you'd need to create a custom type for each group of return types (in effect a struct wrapper) - but these types would have to have arbitrary names due to the lack of struct definitions in the ABI file
Dmitriy Startsev
@dstarcev
Maybe you consider a kind of generic Tuple
Conor Svensson
@conor10
yes, that would be an option
Dmitriy Startsev
@dstarcev
Is there a way to receive new blocks immediately without polling?
Conor Svensson
@conor10
the web3j block Observable takes care of that for you, but is polling behind the scenes. The only other way to receive notification without polling is via a WebSocket connection to Geth (https://github.com/ethereum/go-ethereum/wiki/RPC-PUB-SUB), support for this has not been added to web3j yet
Conor Svensson
@conor10
José Cardoso
@cardosojc
@conor10 i've managed to solve the mentioned issues, thanks for your help! Now, i've another problem..i'm using oraclize, and after invoking oraclize method, oraclize will invoke my contracl callback method which fires an event with the return value, but this process is asynchronous. Using web3j, how can i "wait" for this event? I've used observables and filters, but nothing works.
pragma solidity ^0.4.4;
import "./usingOraclize.sol";

contract QuerySensor is usingOraclize {
    event newOraclizeQuery(string indexed description);
    event newQuerySensor(string indexed price);
    event res(string indexed desc);
    event querySensorStarted(string indexed descp);

      function QuerySensor() {
        querySensorStarted("Query Sensor INITIATED");
    }

    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) throw;
        newQuerySensor(result);
    }

    function update() payable {
        newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
        oraclize_query("URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
    }

    function hw() {
        res("hello world");
    }
}