Java Code Examples for org.web3j.protocol.core.methods.response.EthCall#getValue()

The following examples show how to use org.web3j.protocol.core.methods.response.EthCall#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenRepository.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private String callSmartContractFunction(
        Function function, String contractAddress, NetworkInfo network, Wallet wallet) throws Exception
{
    try
    {
        String encodedFunction = FunctionEncoder.encode(function);

        org.web3j.protocol.core.methods.request.Transaction transaction
                = createEthCallTransaction(wallet.address, contractAddress, encodedFunction);
        EthCall response = getService(network.chainId).ethCall(transaction, DefaultBlockParameterName.LATEST).send();

        return response.getValue();
    }
    catch (InterruptedIOException|UnknownHostException e)
    {
        //expected to happen when user switches wallets
        return "0x";
    }
}
 
Example 2
Source File: TokenRepository.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
/**
 * Call smart contract function on custom network contract. This would be used for things like ENS lookup
 * Currently because it's tied to a mainnet contract address there's no circumstance it would work
 * outside of mainnet. Users may be confused if their namespace doesn't work, even if they're currently
 * using testnet.
 *
 * @param function
 * @param contractAddress
 * @param wallet
 * @return
 */
private String callCustomNetSmartContractFunction(
        Function function, String contractAddress, Wallet wallet, int chainId)  {
    String encodedFunction = FunctionEncoder.encode(function);

    try
    {
        org.web3j.protocol.core.methods.request.Transaction transaction
                = createEthCallTransaction(wallet.address, contractAddress, encodedFunction);
        EthCall response = getService(chainId).ethCall(transaction, DefaultBlockParameterName.LATEST).send();

        return response.getValue();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return null;
    }
}
 
Example 3
Source File: EnsResolver.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private String callSmartContractFunction(
        Function function, String contractAddress, int chainId) throws Exception
{
    try
    {
        String encodedFunction = FunctionEncoder.encode(function);

        org.web3j.protocol.core.methods.request.Transaction transaction
                = createEthCallTransaction(TokenscriptFunction.ZERO_ADDRESS, contractAddress, encodedFunction);
        EthCall response = TokenRepository.getWeb3jService(chainId).ethCall(transaction, DefaultBlockParameterName.LATEST).send();

        return response.getValue();
    }
    catch (InterruptedIOException | UnknownHostException e)
    {
        //expected to happen when user switches wallets
        return "0x";
    }
}
 
Example 4
Source File: PrivCallAcceptanceTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Test
public void mustReturnCorrectValue() throws Exception {

  final String privacyGroupId =
      minerNode.execute(
          privacyTransactions.createPrivacyGroup(
              "myGroupName", "my group description", minerNode));

  final EventEmitter eventEmitter =
      minerNode.execute(
          privateContractTransactions.createSmartContractWithPrivacyGroupId(
              EventEmitter.class,
              minerNode.getTransactionSigningKey(),
              POW_CHAIN_ID,
              minerNode.getEnclaveKey(),
              privacyGroupId));

  privateContractVerifier
      .validPrivateContractDeployed(
          eventEmitter.getContractAddress(), minerNode.getAddress().toString())
      .verify(eventEmitter);

  final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, false, false);

  EthCall resp = priv_call.send();

  String value = resp.getValue();
  assertThat(new BigInteger(value.substring(2), 16)).isEqualByComparingTo(BigInteger.ZERO);

  final TransactionReceipt receipt = eventEmitter.store(BigInteger.valueOf(VALUE)).send();
  assertThat(receipt).isNotNull();

  resp = priv_call.send();
  value = resp.getValue();
  assertThat(new BigInteger(value.substring(2), 16))
      .isEqualByComparingTo(BigInteger.valueOf(VALUE));
}
 
Example 5
Source File: ClientTransactionManager.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter)
        throws IOException {
    EthCall ethCall =
            web3j.ethCall(
                            Transaction.createEthCallTransaction(getFromAddress(), to, data),
                            defaultBlockParameter)
                    .send();

    assertCallNotReverted(ethCall);
    return ethCall.getValue();
}
 
Example 6
Source File: RawTransactionManager.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter)
        throws IOException {
    EthCall ethCall =
            web3j.ethCall(
                            Transaction.createEthCallTransaction(getFromAddress(), to, data),
                            defaultBlockParameter)
                    .send();

    assertCallNotReverted(ethCall);
    return ethCall.getValue();
}
 
Example 7
Source File: ReadonlyTransactionManager.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter)
        throws IOException {
    EthCall ethCall =
            web3j.ethCall(
                            Transaction.createEthCallTransaction(fromAddress, to, data),
                            defaultBlockParameter)
                    .send();

    assertCallNotReverted(ethCall);
    return ethCall.getValue();
}