# Raw Transaction

Let's study the detail of Transaction (opens new window) and Block (opens new window). In this level, you are asked to either guess or set proper parameters of a transaction, like gasPrice, gasLimit, etc.

Please invoke these functions without an error!

function guessBlocknumber(uint _blocknumber);
function guessLastBlockhash(bytes32 _hash)
function guessBalances(uint _myBalance, uint _yourBalance);
function guessWhat(address origin, address sender, uint balance);
function setGasPriceAndGas();

You might want to take a look at how they are implemented. We are not expecting you to fully understand the code (for now!), but many of them look self-explanatory. If you can't figure out what these global variables (e.g., block.number) mean. Take a look at the solidity document (opens new window).

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

contract RawTransaction {
    address public player;
    mapping(string => bool) public status;

    constructor(address _player) payable {
        player = _player;
    }

    function guessLastBlockhash(bytes32 _hash) external {
        require(blockhash(block.number - 1) == _hash);
        status["blockhash"] = true;
    }

    function setGasPriceAndGas() external {
        require(tx.gasprice == 0xfc0effee);
        require(gasleft() > 0xbeef - 0x100 && gasleft() < 0xbeef + 0x100);
        status["gas"] = true;
    }

    function guessBlocknumber(uint _blocknumber) external {
        require(block.number == _blocknumber);
        status["blocknumber"] = true;
    }

    function guessBalances(uint _myBalance, uint _yourBalance) external {
        require(address(this).balance == _myBalance);
        require(address(msg.sender).balance == _yourBalance);
        status["balance"] = true;
    }

    function guessWhat(address origin, address sender) payable external {
        require(msg.value > 0);
        require(origin == tx.origin);
        require(sender == msg.sender);
        status["what"] = true;
    }

    function solved() external returns (bool) {
        return status["blockhash"]
            && status["gas"]
            && status["blocknumber"]
            && status["balance"]
            && status["what"];
    }
}