Ethereum Web3j使用Ganache获取堆栈下溢错误

Ethereum Web3j使用Ganache获取堆栈下溢错误,ethereum,web3,remix,web3-java,ganache,Ethereum,Web3,Remix,Web3 Java,Ganache,我在处理事务时遇到了错误“错误处理事务请求:VM异常:堆栈下溢”,这基本上与任何契约有关。我使用的是Ganache v2.1.2和Web3j 4.5.15。与Ganache CLI v6.9.1(Ganache核心:2.10.2)相同。我能够毫无问题地使用Remix IDE和Metamask插件部署合同 Java代码: public class contractCR { static class OSCGasProvider implements ContractGasProvid

我在处理事务时遇到了错误“错误处理事务请求:VM异常:堆栈下溢”,这基本上与任何契约有关。我使用的是Ganache v2.1.2和Web3j 4.5.15。与Ganache CLI v6.9.1(Ganache核心:2.10.2)相同。我能够毫无问题地使用Remix IDE和Metamask插件部署合同

Java代码:

public class contractCR
  {

    static class OSCGasProvider implements ContractGasProvider
      {     

        public OSCGasProvider(){}

        @Override
        public BigInteger getGasPrice(String string)
          {            
           return Convert.toWei("1", Convert.Unit.GWEI).toBigInteger();             
          }       

        @Override
        public BigInteger getGasLimit(String string)
          {
            return BigInteger.valueOf(3000000);
          }

        @Override
        public BigInteger getGasPrice()
          {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

        @Override
        public BigInteger getGasLimit()
          {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

      }

    public static void main (String args[])
      {
        System.out.println("Connecting to Ethereum ...");
        Web3j web3 = Web3j.build(new HttpService("http://localhost:7545"));
        System.out.println("Successfuly connected to Ethereum");
        try 
          {
            // web3_clientVersion returns the current client version.
            Web3ClientVersion clientVersion = web3.web3ClientVersion().send();
            Credentials credentials=Credentials.create(privateKey);
            Faucet osc = Faucet.deploy(web3, credentials, new OSCGasProvider()).send();
            String contractAddress = osc.getContractAddress();
            System.out.println("The contract address is: "+contractAddress);
           } 
        catch (IOException ex)
          {
            throw new RuntimeException("Error while sending json-rpc requests", ex);
          }
        catch (Exception ex)
          {
              System.out.println(ex.toString());
          }     
      }
}
简单水龙头合同:

// Version of Solidity compiler this program was written for
pragma solidity ^0.5.12;

// Our first contract is a faucet!
contract Faucet {

    address payable owner_addr; //the owner address

    //initialize the contract
    constructor() public 
    {
      owner_addr=msg.sender;
    }

    //contract destructor
    modifier owner_allowed
    {
      require (msg.sender==owner_addr, "Only contract owner is allowed to call this function");    
      _;
    }

    function destroy() public owner_allowed
    {
      selfdestruct(owner_addr);
    }

    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public
     {
        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000); //0.1ether
        // Send the amount to the address that requested it
        msg.sender.transfer(withdraw_amount);
    }

    // Accept any incoming amount
    function () external payable {} //fallback or default function

}
//编写此程序的Solidity编译器版本
pragma坚实度^0.5.12;
//我们的第一份合同是水龙头!
收缩水龙头{
应付所有者地址\u addr;//所有者地址
//初始化合同
构造函数()公共
{
owner\u addr=msg.sender;
}
//合同破坏者
允许修改器所有者\u
{
require(msg.sender==owner\u addr,“只允许合同所有者调用此函数”);
_;
}
函数destroy()允许公共所有者
{
自毁(所有者地址);
}
//向任何要求的人分发乙醚
功能提取(uint提取金额)公共
{
//限额支取金额

要求(提取金额似乎是一个与Ganache相关的问题


根据我的测试,它可以很好地工作,我的本地Ganache 2.1.2终于解决了问题。Web3j cli不接受Remix IDE提供的二进制文件,而只接受“二进制”字段。将只包含二进制数据的文件作为输入提供给Web3j cli会生成正确的包装器。

因此,我想今天没有解决方案。我不确定您是否尝试过以下操作:1.重新启动ganache 2.尝试不同的ganache版本3。使用一个专用geth节点代替ganache。您的代码可以正常工作,无需按照我的操作卡在ganache上意见