0

I am trying to call a function from a modified ERC20 contract and I can't manage to make it work. I am doing this with web3j from Android.

I can connect to Infura. The contract is already deployed on Rinkeby. I checked everything and the address is good. I'm trying to create credentials from a private/public key pair and pass it to use gas from that account.

String publicKey = "0x1900a41f2777ab70aad2074e3F4B9c5429c7f243";
    String privateKey = "some private key";
    String sparkTokenAddr = "some_addr";

    Credentials creds = Credentials.create(privateKey, publicKey);

    SparkToken spark = SparkToken.load(
            sparkTokenAddr, web3, creds, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);

    try {

        TransactionReceipt transactionReceipt = spark.chargedPhone(
                BigInteger.valueOf(50), publicKey).send();

        Log.e("ethereum", String.valueOf(transactionReceipt));

    } catch (Exception e) {
        e.printStackTrace();
        Log.e("ethereum", "Could not send tx");
    }

It always logs that the tx could not be sent. What do I do wrong?

1
  • What's the exception?
    – user19510
    Commented Feb 23, 2018 at 3:25

2 Answers 2

0

This is the code template I generally use to call functions in my smart contract

    contractName.FunctionINeedToCall(function(error, result) {
       if (!error) {
           //Things I want to carry out if there's no error
           console.log(result)
       } else {
            console.log(error);
        }

   });
0

I think your RPC provider has a problem. Do you see any numbers in your "request today" section in infura ? If not,at first change your API method to "websockets" (or "https" if websockets selected before) after that, we have to check other sections of the contract or js.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.