false
false

Contract Address Details

0xC670060dED5057fBeC4D55cCd4446901A3E6E3f0

Contract Name
RandomnessReceiver
Creator
0x582946–2a3fff at 0xa8d970–d433f8
Balance
3.20997253500610282 USC
Tokens
Fetching tokens...
Transactions
10 Transactions
Transfers
0 Transfers
Gas Used
256,227
Last Balance Update
3636389
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
This contract has been partially verified via Sourcify.
Contract name:
RandomnessReceiver




Optimization enabled
true
Compiler version
v0.8.19+commit.7dd6d404




Optimization runs
800
EVM Version
default




Verified at
2024-07-11T13:29:16.527990Z

Contract source code

Sol2uml
new
// SPDX-License-Identifier: UNLICENSED
/* 
                                        
                   .                    
                  .                     
                .  ..                   
               . .+*...                 
             .. :+#%*-..                
            .  -*#%@@%=.. ..            
           . .+##@@#%@@*:.. .           
          . :*%%@%===#@@#-..            
        .. :*%%@#-=%#=*%@%+:..          
       .  :*%@%+-+%%#*+*%@@*:..         
        .-*%@%=-#@@@%#***#%@#-....      
     ...+#%@#-=%@%@@%%+****#@%+:..      
     . =@@@*-*@@@%%@%++%*+++#@@*.       
     . #@@#=#@@@@@%#+*%##*+=+%@@+.      
    . .%@@+*@@@@@@@%#%###**++#@@#. .    
    . .%@%+#@@@@@@@@%%###*+++#@@#. .    
    . .%@%+#%*%@@@@@%%%%*-:+*#@@#. .    
    . .%@%=*@#+%@@@@%%%*-:-+*+@@#. .    
    . .%@#-+@@#=#@@@%%#-:=+*+=%@%. .    
      .*%*-+@@@#=*%@@#-:+**#=-%@%. .    
      .+@#-+@%%@#=+%#-:*##**=-%@%. .    
      .=@%=+@#+%@%==--*#%*+#==%@#. .    
      .+@@=*@@#+%%%+=#%%**@%==@@#. .    
       #@@*##%@#*@%%%%%*#@@***@@%. .    
     . #@@%%%*%@@@@%%@@%@%+##%@@#..     
     . -@@@%@@#%@@@@@@@@#+##%@@@= .     
      ..+@@@@@@#%@@@@@@**%%@@@@+..      
       . -%@@@@%##@@@%*#%@@@@%- .       
        . .*@@@@*+%@%*#@@@@@*. .        
         .  -%@@@++%*+#@@@%=  .         
          .. :#@@@#++#@@@#: ..          
            . .+@@@@@@@@+. .            
             .. :#@@@@#: ..             
              .. .+@@+. .               
                .  ==  .                
                 ..  ..                 
                   ..                   
                                        
    Website: https://EVM.bet
    Twitter: https://x.com/EvmGames                                        

 */

pragma solidity 0.8.19;

/// @notice Interface of the VRF Gateway contract. Must be imported.
interface ISecretVRF {
    function requestRandomness(uint32 _numWords, uint32 _callbackGasLimit)
        external
        payable
        returns (uint256 requestId);
}

interface ILottery {
    /**
     * @notice View current lottery id
     */
    function viewCurrentLotteryId() external returns (uint256);
}

interface IRandomizer {
    /**
     * Requests randomness
     */
    function getRandomNumber(uint32 _callbackGasLimit, uint256 amountOfGas)
        external;

    /**
     * Views random result
     */
    function viewRandomResult() external view returns (uint32);

    /**
     * View latest lotteryId numbers
     */
    function viewLatestLotteryId() external view returns (uint256);
}

contract RandomnessReceiver is IRandomizer {
    /// @notice VRFGateway stores address to the Gateway contract to call for VRF
    address public VRFGateway;

    address public immutable owner;

    uint256 public latestLotteryId;
    uint256 public latestRandomNumber;
    uint256 public latestRequestId;
    uint32 public randomResult;
    address public lottery;

    /// @notice Event that is emitted when a VRF call was made (optional)
    /// @param requestId requestId of the VRF request. Contract can track a VRF call that way
    event requestedRandomness(uint256 requestId);

    event fulfilledRandomWords(uint256 requestId, uint256[] randomWords);

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "UNAUTHORIZED");
        _;
    }

    /// @notice Sets the address to the Gateway contract
    /// @param _VRFGateway address of the gateway
    function setGatewayAddress(address _VRFGateway) external onlyOwner {
        VRFGateway = _VRFGateway;
    }

    /**
     * @notice Set the address for the lottery smart contract
     * @param _lottery: address of the lottery
     */
    function setLotteryAddress(address _lottery) external onlyOwner {
        lottery = _lottery;
    }

    /**
     * @notice View latestLotteryId
     */
    function viewLatestLotteryId() external view override returns (uint256) {
        return latestLotteryId;
    }

    /// @notice function on how to implement a VRF call using Secret VRF
    function getRandomNumber(uint32 _callbackGasLimit, uint256 amountOfGas)
        external
    {
        // Get the VRFGateway contract interface
        ISecretVRF vrfContract = ISecretVRF(VRFGateway);

        require(msg.sender == lottery, "caller not lottery");

        require(address(this).balance >= amountOfGas, "InsufficientFee");

        // Can be up to 2000 random numbers, change this according to your needs
        uint32 numWords = 1;

        // Call the VRF contract to request random numbers.
        // Returns requestId of the VRF request. A  contract can track a VRF call that way.
        latestRequestId = vrfContract.requestRandomness{value: amountOfGas}(
            numWords,
            _callbackGasLimit
        );

        // Emit the event
        emit requestedRandomness(latestRequestId);
    }

    /**
     * @notice View random result
     */
    function viewRandomResult() external view override returns (uint32) {
        return randomResult;
    }

    /*//////////////////////////////////////////////////////////////
                   fulfillRandomWords Callback
    //////////////////////////////////////////////////////////////*/

    /// @notice Callback by the Secret VRF with the requested random numbers
    /// @param requestId requestId of the VRF request that was initally called
    /// @param randomWords Generated Random Numbers in uint256 array
    function fulfillRandomWords(
        uint256 requestId,
        uint256[] calldata randomWords
    ) external {
        // Checks if the callback was called by the VRFGateway and not by any other address
        require(
            msg.sender == address(VRFGateway),
            "only Secret Gateway can fulfill"
        );

        // Do your custom stuff here, for example:
        require(latestRequestId == requestId, "Wrong requestId");

        randomResult = uint32(1000000 + (randomWords[0] % 1000000));

        latestLotteryId = ILottery(lottery).viewCurrentLotteryId();

        latestRandomNumber = randomWords[0];
        emit fulfilledRandomWords(requestId, randomWords);
    }

    receive() external payable {}

    function withdrawStuckXTZ() external onlyOwner {
        (bool success, ) = address(msg.sender).call{
            value: address(this).balance
        }("");
        require(success, "Failed to withdraw stuck XTZ");
    }
}
        

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"fulfilledRandomWords","inputs":[{"type":"uint256","name":"requestId","internalType":"uint256","indexed":false},{"type":"uint256[]","name":"randomWords","internalType":"uint256[]","indexed":false}],"anonymous":false},{"type":"event","name":"requestedRandomness","inputs":[{"type":"uint256","name":"requestId","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"VRFGateway","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"fulfillRandomWords","inputs":[{"type":"uint256","name":"requestId","internalType":"uint256"},{"type":"uint256[]","name":"randomWords","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"getRandomNumber","inputs":[{"type":"uint32","name":"_callbackGasLimit","internalType":"uint32"},{"type":"uint256","name":"amountOfGas","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"latestLotteryId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"latestRandomNumber","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"latestRequestId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"lottery","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint32","name":"","internalType":"uint32"}],"name":"randomResult","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setGatewayAddress","inputs":[{"type":"address","name":"_VRFGateway","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLotteryAddress","inputs":[{"type":"address","name":"_lottery","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"viewLatestLotteryId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint32","name":"","internalType":"uint32"}],"name":"viewRandomResult","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawStuckXTZ","inputs":[]},{"type":"receive","stateMutability":"payable"}]
              

Contract Creation Code

Verify & Publish
0x60a060405234801561001057600080fd5b5033608052608051610a57610045600039600081816101ff015281816102da0152818161056001526107d60152610a576000f3fe6080604052600436106100e15760003560e01c80638da5cb5b1161007f578063a35ff07611610059578063a35ff0761461025c578063ba13a5721461027c578063eed8e1ee146102a4578063fbe5d917146102ba57600080fd5b80638da5cb5b146101ed578063931afbe514610221578063a1c4f55a1461024157600080fd5b80632a332b2a116100bb5780632a332b2a1461016457806338ba46141461018657806342619f66146101a65780638597346f146101d857600080fd5b806316fe73ec146100ed5780631aa46f591461011657806323b311a91461012c57600080fd5b366100e857005b600080fd5b3480156100f957600080fd5b5061010360025481565b6040519081526020015b60405180910390f35b34801561012257600080fd5b5061010360035481565b34801561013857600080fd5b5060005461014c906001600160a01b031681565b6040516001600160a01b03909116815260200161010d565b34801561017057600080fd5b5061018461017f36600461086c565b6102cf565b005b34801561019257600080fd5b506101846101a136600461089c565b61037d565b3480156101b257600080fd5b506004546101c39063ffffffff1681565b60405163ffffffff909116815260200161010d565b3480156101e457600080fd5b50610184610555565b3480156101f957600080fd5b5061014c7f000000000000000000000000000000000000000000000000000000000000000081565b34801561022d57600080fd5b5061018461023c36600461091b565b610657565b34801561024d57600080fd5b5060045463ffffffff166101c3565b34801561026857600080fd5b5061018461027736600461086c565b6107cb565b34801561028857600080fd5b5060045461014c9064010000000090046001600160a01b031681565b3480156102b057600080fd5b5061010360015481565b3480156102c657600080fd5b50600154610103565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461033b5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b600480546001600160a01b03909216640100000000027fffffffffffffffff0000000000000000000000000000000000000000ffffffff909216919091179055565b6000546001600160a01b031633146103d75760405162461bcd60e51b815260206004820152601f60248201527f6f6e6c792053656372657420476174657761792063616e2066756c66696c6c006044820152606401610332565b82600354146104285760405162461bcd60e51b815260206004820152600f60248201527f57726f6e672072657175657374496400000000000000000000000000000000006044820152606401610332565b620f42408282600081811061043f5761043f610950565b905060200201356104509190610966565b61045d90620f4240610988565b600460006101000a81548163ffffffff021916908363ffffffff16021790555060048054906101000a90046001600160a01b03166001600160a01b03166380a061606040518163ffffffff1660e01b81526004016020604051808303816000875af11580156104d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f491906109af565b600155818160008161050857610508610950565b905060200201356002819055507fe7ecfe6928c754cbd5282724cb865166ac3a20565babb867db6047900d723723838383604051610548939291906109c8565b60405180910390a1505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105bc5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610332565b604051600090339047908381818185875af1925050503d80600081146105fe576040519150601f19603f3d011682016040523d82523d6000602084013e610603565b606091505b50509050806106545760405162461bcd60e51b815260206004820152601c60248201527f4661696c656420746f20776974686472617720737475636b2058545a000000006044820152606401610332565b50565b6000546004546001600160a01b03918216913364010000000090920416146106c15760405162461bcd60e51b815260206004820152601260248201527f63616c6c6572206e6f74206c6f747465727900000000000000000000000000006044820152606401610332565b814710156107115760405162461bcd60e51b815260206004820152600f60248201527f496e73756666696369656e7446656500000000000000000000000000000000006044820152606401610332565b6040516361bf619360e01b815260016004820181905263ffffffff85166024830152906001600160a01b038316906361bf619390859060440160206040518083038185885af1158015610768573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061078d91906109af565b60038190556040519081527f9ef465a513d3907321fbc06db999b22497925c91f2cc1ee6b0a52b141d3263b29060200160405180910390a150505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146108325760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610332565b600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b60006020828403121561087e57600080fd5b81356001600160a01b038116811461089557600080fd5b9392505050565b6000806000604084860312156108b157600080fd5b83359250602084013567ffffffffffffffff808211156108d057600080fd5b818601915086601f8301126108e457600080fd5b8135818111156108f357600080fd5b8760208260051b850101111561090857600080fd5b6020830194508093505050509250925092565b6000806040838503121561092e57600080fd5b823563ffffffff8116811461094257600080fd5b946020939093013593505050565b634e487b7160e01b600052603260045260246000fd5b60008261098357634e487b7160e01b600052601260045260246000fd5b500690565b808201808211156109a957634e487b7160e01b600052601160045260246000fd5b92915050565b6000602082840312156109c157600080fd5b5051919050565b8381526040602082015281604082015260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115610a0757600080fd5b8260051b808560608501379190910160600194935050505056fea2646970667358221220a2da6cad090be25a25e851b5e0c254c916f1ee35d029fea93eeea5840f53e48664736f6c63430008130033

Deployed ByteCode

0x6080604052600436106100e15760003560e01c80638da5cb5b1161007f578063a35ff07611610059578063a35ff0761461025c578063ba13a5721461027c578063eed8e1ee146102a4578063fbe5d917146102ba57600080fd5b80638da5cb5b146101ed578063931afbe514610221578063a1c4f55a1461024157600080fd5b80632a332b2a116100bb5780632a332b2a1461016457806338ba46141461018657806342619f66146101a65780638597346f146101d857600080fd5b806316fe73ec146100ed5780631aa46f591461011657806323b311a91461012c57600080fd5b366100e857005b600080fd5b3480156100f957600080fd5b5061010360025481565b6040519081526020015b60405180910390f35b34801561012257600080fd5b5061010360035481565b34801561013857600080fd5b5060005461014c906001600160a01b031681565b6040516001600160a01b03909116815260200161010d565b34801561017057600080fd5b5061018461017f36600461086c565b6102cf565b005b34801561019257600080fd5b506101846101a136600461089c565b61037d565b3480156101b257600080fd5b506004546101c39063ffffffff1681565b60405163ffffffff909116815260200161010d565b3480156101e457600080fd5b50610184610555565b3480156101f957600080fd5b5061014c7f00000000000000000000000058294696ad39d24ac1fd66ca67858b0b562a3fff81565b34801561022d57600080fd5b5061018461023c36600461091b565b610657565b34801561024d57600080fd5b5060045463ffffffff166101c3565b34801561026857600080fd5b5061018461027736600461086c565b6107cb565b34801561028857600080fd5b5060045461014c9064010000000090046001600160a01b031681565b3480156102b057600080fd5b5061010360015481565b3480156102c657600080fd5b50600154610103565b336001600160a01b037f00000000000000000000000058294696ad39d24ac1fd66ca67858b0b562a3fff161461033b5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b600480546001600160a01b03909216640100000000027fffffffffffffffff0000000000000000000000000000000000000000ffffffff909216919091179055565b6000546001600160a01b031633146103d75760405162461bcd60e51b815260206004820152601f60248201527f6f6e6c792053656372657420476174657761792063616e2066756c66696c6c006044820152606401610332565b82600354146104285760405162461bcd60e51b815260206004820152600f60248201527f57726f6e672072657175657374496400000000000000000000000000000000006044820152606401610332565b620f42408282600081811061043f5761043f610950565b905060200201356104509190610966565b61045d90620f4240610988565b600460006101000a81548163ffffffff021916908363ffffffff16021790555060048054906101000a90046001600160a01b03166001600160a01b03166380a061606040518163ffffffff1660e01b81526004016020604051808303816000875af11580156104d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f491906109af565b600155818160008161050857610508610950565b905060200201356002819055507fe7ecfe6928c754cbd5282724cb865166ac3a20565babb867db6047900d723723838383604051610548939291906109c8565b60405180910390a1505050565b336001600160a01b037f00000000000000000000000058294696ad39d24ac1fd66ca67858b0b562a3fff16146105bc5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610332565b604051600090339047908381818185875af1925050503d80600081146105fe576040519150601f19603f3d011682016040523d82523d6000602084013e610603565b606091505b50509050806106545760405162461bcd60e51b815260206004820152601c60248201527f4661696c656420746f20776974686472617720737475636b2058545a000000006044820152606401610332565b50565b6000546004546001600160a01b03918216913364010000000090920416146106c15760405162461bcd60e51b815260206004820152601260248201527f63616c6c6572206e6f74206c6f747465727900000000000000000000000000006044820152606401610332565b814710156107115760405162461bcd60e51b815260206004820152600f60248201527f496e73756666696369656e7446656500000000000000000000000000000000006044820152606401610332565b6040516361bf619360e01b815260016004820181905263ffffffff85166024830152906001600160a01b038316906361bf619390859060440160206040518083038185885af1158015610768573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061078d91906109af565b60038190556040519081527f9ef465a513d3907321fbc06db999b22497925c91f2cc1ee6b0a52b141d3263b29060200160405180910390a150505050565b336001600160a01b037f00000000000000000000000058294696ad39d24ac1fd66ca67858b0b562a3fff16146108325760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610332565b600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b60006020828403121561087e57600080fd5b81356001600160a01b038116811461089557600080fd5b9392505050565b6000806000604084860312156108b157600080fd5b83359250602084013567ffffffffffffffff808211156108d057600080fd5b818601915086601f8301126108e457600080fd5b8135818111156108f357600080fd5b8760208260051b850101111561090857600080fd5b6020830194508093505050509250925092565b6000806040838503121561092e57600080fd5b823563ffffffff8116811461094257600080fd5b946020939093013593505050565b634e487b7160e01b600052603260045260246000fd5b60008261098357634e487b7160e01b600052601260045260246000fd5b500690565b808201808211156109a957634e487b7160e01b600052601160045260246000fd5b92915050565b6000602082840312156109c157600080fd5b5051919050565b8381526040602082015281604082015260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115610a0757600080fd5b8260051b808560608501379190910160600194935050505056fea2646970667358221220a2da6cad090be25a25e851b5e0c254c916f1ee35d029fea93eeea5840f53e48664736f6c63430008130033