Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Return Type #55

Closed
chrismcgregor opened this issue Jun 18, 2020 · 12 comments
Closed

Incorrect Return Type #55

chrismcgregor opened this issue Jun 18, 2020 · 12 comments

Comments

@chrismcgregor
Copy link

chrismcgregor commented Jun 18, 2020

I am using Solc v0.6.9 and we I generate the Java code I am getting the incorrect return type for a few of my ERC20 smart contract functions (e.g., balanceOf).

ERC20 balanceOf function (Solidity code):

function balanceOf(address who) external view returns (uint256);

Java generated method (returns TransactionReceipt):

public RemoteFunctionCall<TransactionReceipt> ERC20BalanceOf(String _erc20Address, String _who) { final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function( FUNC_ERC20BALANCEOF, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _erc20Address), new org.web3j.abi.datatypes.Address(160, _who)), Collections.<TypeReference<?>>emptyList()); return executeRemoteCallTransaction(function); }

Expected Java generated function (returns BigInteger):

public RemoteFunctionCall<BigInteger> ERC20BalanceOf(String _erc20Address, String _who) { final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function( FUNC_ERC20BALANCEOF, Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _erc20Address), new org.web3j.abi.datatypes.Address(160, _who)), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); return executeRemoteCallSingleValueReturn(function, BigInteger.class); }

https://ethereum.stackexchange.com/questions/40730/why-is-web3j-java-not-generating-correct-return-types-for-my-contract

@xaviarias
Copy link
Contributor

In the Stack Exchange example the function is giving the error because is not a view.

Not sure about it but Solidity 0.6.9 but must have a way to mark balanceOf as a view that has changed from prior versions.

Could you attach the generated ABI files?

@chrismcgregor
Copy link
Author

ABI: Abi.txt

Take a look at ERC20BalanceOf() which has a view attribute on the function.

@joaquin-alfaro
Copy link

From solidity 0.6 the property constant included in the ABI has been replaced by the value of stateMutability

The version 4.5.11 of web3j-maven-plugin uses the value of constant to determine if a function is a view

You can wait to the version 4.5.18 of web3j-maven-plugin which probably will solve the problem or make a fork of web3j-maven-plugin and update the version of web3j in pom.xml to 4.5.18
Replace
<web3j.version>4.5.11</web3j.version>
With
<web3j.version>4.5.18</web3j.version>

@chrismcgregor
Copy link
Author

chrismcgregor commented Aug 19, 2020 via email

@chrismcgregor
Copy link
Author

When do you guys plan to release 4.5.18?

@xaviarias
Copy link
Contributor

xaviarias commented Oct 6, 2020

Hi, we just released v4.6.4, can I close this issue?

@chrismcgregor
Copy link
Author

chrismcgregor commented Oct 6, 2020 via email

@xaviarias
Copy link
Contributor

xaviarias commented Oct 6, 2020

Absolutely, thank you! Also, do you know how to generate an Ethereum address from a xpub (extended public key) using Web3j?

final String address = org.web3j.crypto.Keys.getAddress("<public key>")

@chrismcgregor
Copy link
Author

chrismcgregor commented Oct 7, 2020 via email

@chrismcgregor
Copy link
Author

chrismcgregor commented Oct 7, 2020 via email

@xaviarias
Copy link
Contributor

I guess my question is that does Keys.getAddress() support BIP32 or other standards?

Not sure about that, have you tried it? @josh-richardson may have a better answer.

@chrismcgregor
Copy link
Author

chrismcgregor commented Oct 8, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants