Not able to deploy smart contract on testrpc

0 votes

Not able to deploy smart contract on testrpc.

My solidity contract is as follows:

pragma solidity ^0.4.11;

contract Fibonacci {

    event Notify(uint input, uint result);

    function fibonacci(uint number) constant returns(uint result) {
        if (number == 0) return 0;
        else if (number == 1) return 1;
        else return Fibonacci.fibonacci(number - 1) + Fibonacci.fibonacci(number - 2);
    }

    function fibonacciNotify(uint number) returns(uint result) {
        result = fibonacci(number);
        Notify(number, result);
    }
}

The Java code to deploy this contract:
Future<FibonacciZKF> fib= FibonacciZKF.deploy(Web3j.build(new HttpService()), ALICE, GAS_PRICE, GAS_LIMIT, BigInteger.valueOf(5));

The wrapper for my contract is:

public final class Fibonacci extends Contract {
    private static final String BINARY = "6060604052341561000f57600080fd5b5b61015a8061001f6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633c7fdc70811461004857806361047ff414610070575b600080fd5b341561005357600080fd5b61005e600435610098565b60405190815260200160405180910390f35b341561007b57600080fd5b61005e6004356100e5565b60405190815260200160405180910390f35b60006100a3826100e5565b90507f71e71a8458267085d5ab16980fd5f114d2d37f232479c245d523ce8d23ca40ed828260405191825260208201526040908101905180910390a15b919050565b60008115156100f6575060006100e0565b8160011415610107575060016100e0565b610113600283036100e5565b61011f600184036100e5565b0190506100e0565b5b5b9190505600a165627a7a723058208c691bf2e824f14fefeb8b2e4932d9a9122cbe5835242992958daf1fc4a81af60029";

private Fibonacci(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}

private Fibonacci(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}

public List<NotifyEventResponse> getNotifyEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Notify", 
            Arrays.<TypeReference<?>>asList(),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<NotifyEventResponse> responses = new ArrayList<NotifyEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        NotifyEventResponse typedResponse = new NotifyEventResponse();
        typedResponse.input = (Uint256) eventValues.getNonIndexedValues().get(0);
        typedResponse.result = (Uint256) eventValues.getNonIndexedValues().get(1);
        responses.add(typedResponse);
    }
    return responses;
}

public Observable<NotifyEventResponse> notifyEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("Notify", 
            Arrays.<TypeReference<?>>asList(),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, NotifyEventResponse>() {
        @Override
        public NotifyEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            NotifyEventResponse typedResponse = new NotifyEventResponse();
            typedResponse.input = (Uint256) eventValues.getNonIndexedValues().get(0);
            typedResponse.result = (Uint256) eventValues.getNonIndexedValues().get(1);
            return typedResponse;
        }
    });
}

public Future<TransactionReceipt> fibonacciNotify(Uint256 number) {
    Function function = new Function("fibonacciNotify", Arrays.<Type>asList(number), Collections.<TypeReference<?>>emptyList());
    return executeTransactionAsync(function);
}

public Future<Uint256> fibonacci(Uint256 number) {
    Function function = new Function("fibonacci", 
            Arrays.<Type>asList(number), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeCallSingleValueReturnAsync(function);
}

public static Future<Fibonacci> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
    return deployAsync(Fibonacci.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}

public static Future<Fibonacci> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
    return deployAsync(Fibonacci.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}

public static Fibonacci load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
    return new Fibonacci(contractAddress, web3j, credentials, gasPrice, gasLimit);
}

public static Fibonacci load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
    return new Fibonacci(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}

public static class NotifyEventResponse {
    public Uint256 input;

    public Uint256 result;
}

But the contract is not getting deployed. Please help

Jul 23, 2018 in Blockchain by slayer
• 29,350 points
533 views

1 answer to this question.

0 votes

I attached to geth using the following code:

 try {
        web3j = Web3j.build(new HttpService("Http://localhost:8545"));
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }

Check whether the client is connected to the testnet and is running a node and also check if client is attached 
to a geth that is connected to the testnet.

answered Jul 23, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Not able to deploy smart contract to private network

This could happen due to 3 possible ...READ MORE

answered Jan 18, 2019 in Blockchain by Omkar
• 69,210 points
710 views
0 votes
1 answer

Not being able to deploy blockchain demo app on bluemix

The car lease demo's "Deploy to Bluemix" ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,400 points
483 views
0 votes
1 answer

Not able to set up the testrpc or geth client on ubuntu

The commands you have used installs Ethereum ...READ MORE

answered Feb 8, 2019 in Blockchain by Omkar
• 69,210 points
578 views
+1 vote
1 answer

How to deploy ethereum smart contracts on a website?

There are many ways to do this: 1 ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
1,642 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,663 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer
0 votes
1 answer

Not able to execute a deployed contract?

The problem is that you are not ...READ MORE

answered Jul 30, 2018 in Blockchain by digger
• 26,740 points
458 views
0 votes
1 answer

How to use real world/live data in my smart contract?

You cant access/embed real world data using ...READ MORE

answered Jul 12, 2018 in Blockchain by digger
• 26,740 points
890 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP