首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RuntimeError: abort([object对象])。有关更多信息,请使用-s ASSERTIONS=1构建

RuntimeError: abort([object对象])。有关更多信息,请使用-s ASSERTIONS=1构建
EN

Ethereum用户
提问于 2021-06-08 04:59:19
回答 1查看 545关注 0票数 0

我看到了一个类似的问题,但没有解决我的问题。这是我基于研究的合同代码。

代码语言:javascript
运行
复制
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <=0.8.4;

contract Lottery {
    // address payable is the same as address, but have transfer and send members.
    address payable public manager;
    address payable[]  public players;
    
    constructor (){
        // msg.sender is an address where the current function call came from
        manager = payable(msg.sender);
    }
    
    function enter() public payable {
        //  msg.value is the amount of wei sent with the message to the contract
        require(msg.value > .01 ether);
        players.push(payable(msg.sender));
    }
    
    function random() private view returns (uint) {
        return uint(keccak256(abi.encodePacked(block.difficulty,block.timestamp)));

    }
    
    function pickWinner() public restricted {
        uint index = random() % players.length;
        // transfer reverts on failure
        players[index].transfer(address(this).balance);
        // resets the array
        players = new address payable[](0);
    }
    
    modifier restricted() {
        require(msg.sender == manager);
        _;
    }
    
    function getPlayers() public view returns (address payable[] memory ) {
        return players;
    }
}   

这是一个错误:

代码语言:javascript
运行
复制
RuntimeError: abort([object Object]). Build with -s ASSERTIONS=1 for more info.
    at process.abort (/home/projects/ethereum/lottery/node_modules/solc/soljson.js:1:13012)

我检查了"solc/soljson“第一个字母为"null”。

我检查了solc,有一个类似的问题,但仍然是开放的:https://github.com/ethereum/solc-js/issues/493

编译和测试这项工作是有效的。但问题在于部署。这是deploy.js

代码语言:javascript
运行
复制
const HDWalletProvider = require("@truffle/hdwallet-provider");
const Web3 = require("web3");
const { abi, evm } = require("./compile");
const config = require("./config");

const bytecode = evm.bytecode.object;
const abi_string = JSON.stringify(abi);

const metamask_mnemonic = config.metamask_mnemonic;

const ropsten_network = config.ropsten_network;
const provider = new HDWalletProvider({
  mnemonic: {
    phrase: metamask_mnemonic,
  },
  providerOrUrl: ropsten_network,
});

const web3 = new Web3(provider);

const deploy = async () => {
  const accounts = await web3.eth.getAccounts();

  console.log("Attempting to deploy from account", accounts[0]);

  const result = await new web3.eth.Contract(JSON.parse(abi_string))
    .deploy({ data: "0x" + bytecode })
    .send({ gas: "1000000", from: accounts[0] });

  // this address is used in etherscan to find the account
  console.log("Contract deployed to" + result.options.address);
  // console.log("ABI:" + abi_string);
};
deploy();

这是abi_string:

代码语言:javascript
运行
复制
abi_String [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"enter","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPlayers","outputs":[{"internalType":"address payable[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pickWinner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"players","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

此帐户为0:

代码语言:javascript
运行
复制
Attempting to deploy from account 0x3FB83280e44B4c1b77E8fb3ce6e0E1C271BE1659
EN

回答 1

Ethereum用户

回答已采纳

发布于 2021-06-11 01:38:12

我在try/catch块中编写了部署():

代码语言:javascript
运行
复制
const deploy = async () => {
  try {
    const accounts = await web3.eth.getAccounts();

    console.log("Attempting to deploy from account", accounts[0]);

    const result = await new web3.eth.Contract(JSON.parse(abi_string))
      .deploy({ data: "0x" + bytecode })
      .send({ from: accounts[0], gas: "1000000" });

    // this address is used in etherscan to find the account
    console.log("Contract deployed to", result.options.address);
    console.log("ABI:" + abi_string);
  } catch (error) {
    console.log(error);
  }
};

catch()阻止记录此错误:

代码语言:javascript
运行
复制
{ code: -32000, message: 'insufficient funds for gas * price + value' }

所以我访问这个水龙头,把一些乙醚转移到accounts[0]

https://faucet.ropsten.be/

成功部署

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/101518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档