Categories
Cryptocurrency Ethereum Mastering Development

How to solve the problem: java.lang.RuntimeException: Error processing transaction request: VM Exception while processing transaction: stack underflow

I generated JAVA wrapper solidity code.
I am trying to deploy my contract on our local Ethereum blockchain and and get the following error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.bouncycastle.jcajce.provider.drbg.DRBG (file:/C:/Users/79278/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.61/bcprov-jdk15on-1.61.jar) to constructor sun.security.provider.Sun()
WARNING: Please consider reporting this to the maintainers of org.bouncycastle.jcajce.provider.drbg.DRBG
WARNING: Use –illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
EthereumJS TestRPC/v2.13.0/ethereum-js
Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Error processing transaction request: VM Exception while processing transaction: stack underflow
at org.web3j.tx.Contract.deploy(Contract.java:449)
at org.web3j.tx.Contract.deploy(Contract.java:495)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:538)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at Main.deployContract(Main.java:41)
at Main.(Main.java:29)
at Main.main(Main.java:21)
Caused by: java.lang.RuntimeException: Error processing transaction request: VM Exception while processing transaction: stack underflow
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:106)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:76)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:114)
at org.web3j.tx.Contract.executeTransaction(Contract.java:362)
at org.web3j.tx.Contract.create(Contract.java:411)
at org.web3j.tx.Contract.deploy(Contract.java:445)
… 6 more

This is my code:

mport org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.DefaultGasProvider;
import web3developer.Migrations;
import web3developer.SolidityContract;

import java.io.IOException;
import java.math.BigInteger;

public class Main {

public static void main(String[] args) throws Exception {

    new Main();

}

public Main() throws Exception {
    Web3j web3j = Web3j.build(new HttpService("HTTP://127.0.0.1:8545"));
    Credentials credentials = Credentials.create("0x9d2ac2a9d23fe05414b566bc7ff72c3058f3ecb835a4fab145d748b214bca847");
    clientVersion(web3j);
    deployContract(web3j, credentials);
}

public void clientVersion(Web3j web3j) throws IOException {

    Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().send();
    String clientVersion = web3ClientVersion.getWeb3ClientVersion();
    System.out.println(clientVersion);
}

public String deployContract(Web3j web3j, Credentials credentials) throws Exception {
   return SolidityContract.deploy(web3j, credentials, DefaultGasProvider.GAS_PRICE, DefaultGasProvider.GAS_LIMIT).send().getContractAddress();
}

}

This is my JAVA wrapper code:

package web3developer;

import io.reactivex.Flowable;
import io.reactivex.functions.Function;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;

/**

  • Auto generated code.

  • Do not modify!

  • Please use the web3j command line tools,

  • or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
  • codegen module to update.
  • Generated with web3j version 4.0.1.

*/
public class SolidityContract extends Contract {
private static final String BINARY = "{\r\n"
+ "\t"generatedSources": [],\r\n"
+ "\t"linkReferences": {},\r\n"
+ "\t"object": "608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061047f806100606000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063075461721461005157806327e235e31461008557806340c10f19146100dd578063d0679d341461012b575b600080fd5b610059610179565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100c76004803603602081101561009b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061019d565b6040518082815260200191505060405180910390f35b610129600480360360408110156100f357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101b5565b005b6101776004803603604081101561014157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610283565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60016020528060005260406000206000915090505481565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461020d57600080fd5b789f4f2726179a224501d762422c946590d91000000000000000811061023257600080fd5b80600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055505050565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054811115610338576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f496e73756666696369656e742062616c616e63652e000000000000000000000081525060200191505060405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555080600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055507f3990db2d31862302a685e8086b5755072a6e2b5b780af1ee81ece35ee3cd3345338383604051808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a1505056fea26469706673582212209a308532cb8864fb8eab5d3b9334575c396ca2112a716a2914b7d3069eb0f2b464736f6c63430007030033",\r\n"
+ "\t"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP CALLER PUSH1 0x0 DUP1 PUSH2 0x100 EXP DUP2 SLOAD DUP2 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF MUL NOT AND SWAP1 DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND MUL OR SWAP1 SSTORE POP PUSH2 0x47F DUP1 PUSH2 0x60 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x4C JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x7546172 EQ PUSH2 0x51 JUMPI DUP1 PUSH4 0x27E235E3 EQ PUSH2 0x85 JUMPI DUP1 PUSH4 0x40C10F19 EQ PUSH2 0xDD JUMPI DUP1 PUSH4 0xD0679D34 EQ PUSH2 0x12B JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x59 PUSH2 0x179 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0xC7 PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x20 DUP2 LT ISZERO PUSH2 0x9B JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0x19D JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x129 PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x40 DUP2 LT ISZERO PUSH2 0xF3 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 DUP1 CALLDATALOAD SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0x1B5 JUMP JUMPDEST STOP JUMPDEST PUSH2 0x177 PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x40 DUP2 LT ISZERO PUSH2 0x141 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 DUP1 CALLDATALOAD SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0x283 JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 PUSH2 0x100 EXP SWAP1 DIV PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 JUMP JUMPDEST PUSH1 0x1 PUSH1 0x20 MSTORE DUP1 PUSH1 0x0 MSTORE PUSH1 0x40 PUSH1 0x0 KECCAK256 PUSH1 0x0 SWAP2 POP SWAP1 POP SLOAD DUP2 JUMP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 PUSH2 0x100 EXP SWAP1 DIV PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND EQ PUSH2 0x20D JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH25 0x9F4F2726179A224501D762422C946590D91000000000000000 DUP2 LT PUSH2 0x232 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP1 PUSH1 0x1 PUSH1 0x0 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x0 KECCAK256 PUSH1 0x0 DUP3 DUP3 SLOAD ADD SWAP3 POP POP DUP2 SWAP1 SSTORE POP POP POP JUMP JUMPDEST PUSH1 0x1 PUSH1 0x0 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x0 KECCAK256 SLOAD DUP2 GT ISZERO PUSH2 0x338 JUMPI PUSH1 0x40 MLOAD PUSH32 0x8C379A000000000000000000000000000000000000000000000000000000000 DUP2 MSTORE PUSH1 0x4 ADD DUP1 DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE PUSH1 0x15 DUP2 MSTORE PUSH1 0x20 ADD DUP1 PUSH32 0x496E73756666696369656E742062616C616E63652E0000000000000000000000 DUP2 MSTORE POP PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 REVERT JUMPDEST DUP1 PUSH1 0x1 PUSH1 0x0 CALLER PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x0 KECCAK256 PUSH1 0x0 DUP3 DUP3 SLOAD SUB SWAP3 POP POP DUP2 SWAP1 SSTORE POP DUP1 PUSH1 0x1 PUSH1 0x0 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP1 DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x0 KECCAK256 PUSH1 0x0 DUP3 DUP3 SLOAD ADD SWAP3 POP POP DUP2 SWAP1 SSTORE POP PUSH32 0x3990DB2D31862302A685E8086B5755072A6E2B5B780AF1EE81ECE35EE3CD3345 CALLER DUP4 DUP4 PUSH1 0x40 MLOAD DUP1 DUP5 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP4 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP4 POP POP POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 POP POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 SWAP11 ADDRESS DUP6 ORIGIN 0xCB DUP9 PUSH5 0xFB8EAB5D3B SWAP4 CALLVALUE JUMPI 0x5C CODECOPY PUSH13 0xA2112A716A2914B7D3069EB0F2 0xB4 PUSH5 0x736F6C6343 STOP SMOD SUB STOP CALLER ",\r\n"
+ "\t"sourceMap": "72:1116:0:-:0;;;487:52;;;;;;;;;;521:10;512:6;;:19;;;;;;;;;;;;;;;;;;72:1116;;;;;;"\r\n"
+ "}";

public static final String FUNC_BALANCES = "balances";

public static final String FUNC_MINT = "mint";

public static final String FUNC_MINTER = "minter";

public static final String FUNC_SEND = "send";

public static final Event SENT_EVENT = new Event("Sent", 
        Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}));
;

@Deprecated
protected SolidityContract(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}

protected SolidityContract(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}

@Deprecated
protected SolidityContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}

protected SolidityContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}

public List<SentEventResponse> getSentEvents(TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(SENT_EVENT, transactionReceipt);
    ArrayList<SentEventResponse> responses = new ArrayList<SentEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        SentEventResponse typedResponse = new SentEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse.from = (String) eventValues.getNonIndexedValues().get(0).getValue();
        typedResponse.to = (String) eventValues.getNonIndexedValues().get(1).getValue();
        typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
        responses.add(typedResponse);
    }
    return responses;
}

public Flowable<SentEventResponse> sentEventFlowable(EthFilter filter) {
    return web3j.ethLogFlowable(filter).map(new Function<Log, SentEventResponse>() {
        @Override
        public SentEventResponse apply(Log log) {
            Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(SENT_EVENT, log);
            SentEventResponse typedResponse = new SentEventResponse();
            typedResponse.log = log;
            typedResponse.from = (String) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.to = (String) eventValues.getNonIndexedValues().get(1).getValue();
            typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
            return typedResponse;
        }
    });
}

public Flowable<SentEventResponse> sentEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(SENT_EVENT));
    return sentEventFlowable(filter);
}

public RemoteCall<TransactionReceipt> balances(String param0) {
    final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
            FUNC_BALANCES, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(param0)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}

public RemoteCall<TransactionReceipt> mint(String receiver, BigInteger amount) {
    final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
            FUNC_MINT, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(receiver), 
            new org.web3j.abi.datatypes.generated.Uint256(amount)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}

public RemoteCall<TransactionReceipt> minter() {
    final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
            FUNC_MINTER, 
            Arrays.<Type>asList(), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}

public RemoteCall<TransactionReceipt> send(String receiver, BigInteger amount) {
    final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
            FUNC_SEND, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(receiver), 
            new org.web3j.abi.datatypes.generated.Uint256(amount)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}

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

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

public static SolidityContract load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
    return new SolidityContract(contractAddress, web3j, credentials, contractGasProvider);
}

public static SolidityContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
    return new SolidityContract(contractAddress, web3j, transactionManager, contractGasProvider);
}

public static RemoteCall<SolidityContract> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
    return deployRemoteCall(SolidityContract.class, web3j, credentials, contractGasProvider, BINARY, "");
}

How can I solve this problem? Thank you in advance

Leave a Reply

Your email address will not be published. Required fields are marked *