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?

  • What's the exception? – user19510 Feb 23 '18 at 3:25
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);
        }

   });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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