0

好的,我们开始吧。我是一个非常新手的业余编码爱好者,但我最近深入研究了加密货币世界,并且我正在努力至少熟悉 Solidity 智能合约。这是一个defi游戏的代码。这段代码的重点是生成“硬币翻转”。我觉得它创造的赢家多于输家。此外,考虑到它使用用户公共钱包地址(msg.sender)“常量数字”作为函数的基础时,此代码是否不会产生相同的结果?

请思考,谢谢!

对于 msg.sender 变量,您可以使用 ERC-20 钱包地址,即

0xA2C8EB70b58D57Db442a2395e8aB80b640C655a7

如果需要整个合同,可以在这里找到。

https://bscscan.com/address/0xc4661ce2ef5dd31a1e020985e7364708c1af03d5#code

  //address(this).balance is increased by msg.value even before code is executed. Thus "address(this).balance-msg.value"
    //Create a random number. Use the mining difficulty & the player's address, hash it, convert this hex to int, divide by modulo 2 which results in either 0 or 1 and return as uint8
    uint8 result = uint8(uint256(keccak256(abi.encodePacked(block.difficulty, msg.sender, block.timestamp)))%2);
    bool won = false;
    if (guess == result) {
      won = true;
      uint256 win = (amount* 2/100*(100-houseedge));
       tokenpiggies.transfer(msg.sender, win-amount);
    }else{
        tokenpiggies.transferFrom(msg.sender, address(this), amount);  
    }

    emit GameResult(result);
    lastPlayedGames.push(Game(msg.sender, amount, guess,3, won, block.timestamp));
    return won; //Return value can only be used by other functions, but not within web3.js (as of 2019)
  }
4

0 回答 0