English 中文(简体)
false Transaction mined but execution failed in Remix IDE
原标题:

I am getting false Transaction mined but execution failed error from the constructor function in the contract. I am just saving the address from which the contract is deployed in manager variable and not sending any money to the account.

   // SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.20;

contract Lottery{
    address public manager;
    address[] public players;

    constructor() public {
        manager = msg.sender;
    }

    function enter()public payable{
        require(msg.value > 0.1 ether);
        players.push(msg.sender);
    }

//Random number generator function.
    function random()private view returns (uint){
        return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
    }

    function pickWinner()public{
        uint index = random() % players.length;
        address contractAddress = address(this);
        payable(players[index]).transfer(contractAddress.balance);
    }

}

After solidity v0.7, it says that visibility of the constructor is not required, so i tried by removing the publicvisibility. I also tried with payable visibility to the constructor() but still getting the same error.

问题回答

try this one below

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;

contract Lottery {
    address public manager;
    address[] public players;

    constructor() {
        manager = msg.sender;
    }

    function enter() public payable {
        require(msg.value > 0.1 ether);
        players.push(msg.sender);
    }

    // Random number generator function.
    function random() private view returns (uint) {
        return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
    }

    function pickWinner() public {
        uint index = random() % players.length;
        address payable winner = payable(players[index]);
        uint contractBalance = address(this).balance;
        winner.transfer(contractBalance);
        players = new address[](0); // Reset the player array for a new round
    }
}




相关问题
ERC20 津贴不足

我非常经常地问这个问题。 我道歉,但我不理解许多答案。 我曾试图订立一项契约,但这一错误使我陷入了境地。 ......

Web3.js sendSignedTransaction Problem...... plz help me

i use ganache-cli for operate node in local environment. after that I wrote Smart contract solidity code in remix. And then, deployed in my ganache node. And deployed log was successful in my ganache. ...

unable to get data from blockchain using thirdweb

I am building a simple crowdfunding app using React and thirdweb , I was able to successfully create a Campaign mean data is pushed successfully , I have read docs everything works fine , but when i ...

false Transaction mined but execution failed in Remix IDE

I am getting false Transaction mined but execution failed error from the constructor function in the contract. I am just saving the address from which the contract is deployed in manager variable and ...

TypeError: (0 , ethers_1.getAddress) is not a function

I am getting this error while deploying my smart contract const main = async() => { const contractFactory = await ethers.getContractFactory( TwitterContract ); const contract = await ...

ETH sendSignedTransaction

I Try to use @ethereumjs/tx to sign Transaction. I want to send ETH from one address to second address. .... const legacy = require( @ethereumjs/tx/dist/legacyTransaction ); const utils = require( ...

热门标签