0

I saw a similar question but does not solve my issue. here is my contract code based on my research.

// 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;
    }
}   

this is the error:

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)

I checked "solc/soljson" first letter was "null".

I checked solc github repo and there is a similar issue but still open: https://github.com/ethereum/solc-js/issues/493

compiling and testing this work is working. but the issue is with deploying. here is the deploy.js

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();

this is abi_string:

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"}]

this accounts[0]:

Attempting to deploy from account 0x3FB83280e44B4c1b77E8fb3ce6e0E1C271BE1659

enter image description here

0

I wrote the deploy() in try/catch block:

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() block logged this error:

{ code: -32000, message: 'insufficient funds for gas * price + value' }

So I visit this faucet to transfer some ether to accounts[0]

https://faucet.ropsten.be/

Successfully deployed

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.