Contract 0x039781cb7fEfD7CaF3012D73a54530C42Cc4Bc91 1

Contract Overview

Balance:
0 MATIC
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xb9ca19a7b62c8a3ed184db70d1ed70111c404f6492fcd3a9958716a6177acfb5Request Random N...239130302022-01-15 12:58:5813 days 5 hrs ago0x7975b07ae585fe1f88b80d2b5ad154af9e5dfc24 IN  0x039781cb7fefd7caf3012d73a54530c42cc4bc910 MATIC0.037407241981 1.999999999
0x7217cf21c167592d839634bb16662a9a02438ff2a9b33b298aee4d844d033c9e0x60c06040239129732022-01-15 12:55:2013 days 5 hrs ago0x7975b07ae585fe1f88b80d2b5ad154af9e5dfc24 IN  Create: RandomTest0 MATIC0.001422022505 2.50000001
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
RandomTest

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 4 : RandomTest.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8;
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

contract RandomTest is VRFConsumerBase {

    bytes32 internal keyHash;
    uint256 public fee;

    uint256[] public randomNumbers;

    constructor(address _VRFCoordinator, address _LinkToken, bytes32 _keyHash)
    VRFConsumerBase(_VRFCoordinator, _LinkToken)
    {
        keyHash = _keyHash;
        fee = 0.0001 * 10 ** 18; // 0.1 LINK
    }

    function requestRandomNumber () public returns (bytes32) {
        bytes32 requestId = requestRandomness(keyHash, fee);
        return requestId;
    }

    function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override {
        randomNumbers.push(randomNumber);
    }

}

File 2 of 4 : LinkTokenInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface LinkTokenInterface {
  function allowance(address owner, address spender) external view returns (uint256 remaining);

  function approve(address spender, uint256 value) external returns (bool success);

  function balanceOf(address owner) external view returns (uint256 balance);

  function decimals() external view returns (uint8 decimalPlaces);

  function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);

  function increaseApproval(address spender, uint256 subtractedValue) external;

  function name() external view returns (string memory tokenName);

  function symbol() external view returns (string memory tokenSymbol);

  function totalSupply() external view returns (uint256 totalTokensIssued);

  function transfer(address to, uint256 value) external returns (bool success);

  function transferAndCall(
    address to,
    uint256 value,
    bytes calldata data
  ) external returns (bool success);

  function transferFrom(
    address from,
    address to,
    uint256 value
  ) external returns (bool success);
}

File 3 of 4 : VRFRequestIDBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract VRFRequestIDBase {
  /**
   * @notice returns the seed which is actually input to the VRF coordinator
   *
   * @dev To prevent repetition of VRF output due to repetition of the
   * @dev user-supplied seed, that seed is combined in a hash with the
   * @dev user-specific nonce, and the address of the consuming contract. The
   * @dev risk of repetition is mostly mitigated by inclusion of a blockhash in
   * @dev the final seed, but the nonce does protect against repetition in
   * @dev requests which are included in a single block.
   *
   * @param _userSeed VRF seed input provided by user
   * @param _requester Address of the requesting contract
   * @param _nonce User-specific nonce at the time of the request
   */
  function makeVRFInputSeed(
    bytes32 _keyHash,
    uint256 _userSeed,
    address _requester,
    uint256 _nonce
  ) internal pure returns (uint256) {
    return uint256(keccak256(abi.encode(_keyHash, _userSeed, _requester, _nonce)));
  }

  /**
   * @notice Returns the id for this request
   * @param _keyHash The serviceAgreement ID to be used for this request
   * @param _vRFInputSeed The seed to be passed directly to the VRF
   * @return The id for this request
   *
   * @dev Note that _vRFInputSeed is not the seed passed by the consuming
   * @dev contract, but the one generated by makeVRFInputSeed
   */
  function makeRequestId(bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) {
    return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed));
  }
}

File 4 of 4 : VRFConsumerBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./interfaces/LinkTokenInterface.sol";

import "./VRFRequestIDBase.sol";

/** ****************************************************************************
 * @notice Interface for contracts using VRF randomness
 * *****************************************************************************
 * @dev PURPOSE
 *
 * @dev Reggie the Random Oracle (not his real job) wants to provide randomness
 * @dev to Vera the verifier in such a way that Vera can be sure he's not
 * @dev making his output up to suit himself. Reggie provides Vera a public key
 * @dev to which he knows the secret key. Each time Vera provides a seed to
 * @dev Reggie, he gives back a value which is computed completely
 * @dev deterministically from the seed and the secret key.
 *
 * @dev Reggie provides a proof by which Vera can verify that the output was
 * @dev correctly computed once Reggie tells it to her, but without that proof,
 * @dev the output is indistinguishable to her from a uniform random sample
 * @dev from the output space.
 *
 * @dev The purpose of this contract is to make it easy for unrelated contracts
 * @dev to talk to Vera the verifier about the work Reggie is doing, to provide
 * @dev simple access to a verifiable source of randomness.
 * *****************************************************************************
 * @dev USAGE
 *
 * @dev Calling contracts must inherit from VRFConsumerBase, and can
 * @dev initialize VRFConsumerBase's attributes in their constructor as
 * @dev shown:
 *
 * @dev   contract VRFConsumer {
 * @dev     constuctor(<other arguments>, address _vrfCoordinator, address _link)
 * @dev       VRFConsumerBase(_vrfCoordinator, _link) public {
 * @dev         <initialization with other arguments goes here>
 * @dev       }
 * @dev   }
 *
 * @dev The oracle will have given you an ID for the VRF keypair they have
 * @dev committed to (let's call it keyHash), and have told you the minimum LINK
 * @dev price for VRF service. Make sure your contract has sufficient LINK, and
 * @dev call requestRandomness(keyHash, fee, seed), where seed is the input you
 * @dev want to generate randomness from.
 *
 * @dev Once the VRFCoordinator has received and validated the oracle's response
 * @dev to your request, it will call your contract's fulfillRandomness method.
 *
 * @dev The randomness argument to fulfillRandomness is the actual random value
 * @dev generated from your seed.
 *
 * @dev The requestId argument is generated from the keyHash and the seed by
 * @dev makeRequestId(keyHash, seed). If your contract could have concurrent
 * @dev requests open, you can use the requestId to track which seed is
 * @dev associated with which randomness. See VRFRequestIDBase.sol for more
 * @dev details. (See "SECURITY CONSIDERATIONS" for principles to keep in mind,
 * @dev if your contract could have multiple requests in flight simultaneously.)
 *
 * @dev Colliding `requestId`s are cryptographically impossible as long as seeds
 * @dev differ. (Which is critical to making unpredictable randomness! See the
 * @dev next section.)
 *
 * *****************************************************************************
 * @dev SECURITY CONSIDERATIONS
 *
 * @dev A method with the ability to call your fulfillRandomness method directly
 * @dev could spoof a VRF response with any random value, so it's critical that
 * @dev it cannot be directly called by anything other than this base contract
 * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).
 *
 * @dev For your users to trust that your contract's random behavior is free
 * @dev from malicious interference, it's best if you can write it so that all
 * @dev behaviors implied by a VRF response are executed *during* your
 * @dev fulfillRandomness method. If your contract must store the response (or
 * @dev anything derived from it) and use it later, you must ensure that any
 * @dev user-significant behavior which depends on that stored value cannot be
 * @dev manipulated by a subsequent VRF request.
 *
 * @dev Similarly, both miners and the VRF oracle itself have some influence
 * @dev over the order in which VRF responses appear on the blockchain, so if
 * @dev your contract could have multiple VRF requests in flight simultaneously,
 * @dev you must ensure that the order in which the VRF responses arrive cannot
 * @dev be used to manipulate your contract's user-significant behavior.
 *
 * @dev Since the ultimate input to the VRF is mixed with the block hash of the
 * @dev block in which the request is made, user-provided seeds have no impact
 * @dev on its economic security properties. They are only included for API
 * @dev compatability with previous versions of this contract.
 *
 * @dev Since the block hash of the block which contains the requestRandomness
 * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful
 * @dev miner could, in principle, fork the blockchain to evict the block
 * @dev containing the request, forcing the request to be included in a
 * @dev different block with a different hash, and therefore a different input
 * @dev to the VRF. However, such an attack would incur a substantial economic
 * @dev cost. This cost scales with the number of blocks the VRF oracle waits
 * @dev until it calls responds to a request.
 */
abstract contract VRFConsumerBase is VRFRequestIDBase {
  /**
   * @notice fulfillRandomness handles the VRF response. Your contract must
   * @notice implement it. See "SECURITY CONSIDERATIONS" above for important
   * @notice principles to keep in mind when implementing your fulfillRandomness
   * @notice method.
   *
   * @dev VRFConsumerBase expects its subcontracts to have a method with this
   * @dev signature, and will call it once it has verified the proof
   * @dev associated with the randomness. (It is triggered via a call to
   * @dev rawFulfillRandomness, below.)
   *
   * @param requestId The Id initially returned by requestRandomness
   * @param randomness the VRF output
   */
  function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual;

  /**
   * @dev In order to keep backwards compatibility we have kept the user
   * seed field around. We remove the use of it because given that the blockhash
   * enters later, it overrides whatever randomness the used seed provides.
   * Given that it adds no security, and can easily lead to misunderstandings,
   * we have removed it from usage and can now provide a simpler API.
   */
  uint256 private constant USER_SEED_PLACEHOLDER = 0;

  /**
   * @notice requestRandomness initiates a request for VRF output given _seed
   *
   * @dev The fulfillRandomness method receives the output, once it's provided
   * @dev by the Oracle, and verified by the vrfCoordinator.
   *
   * @dev The _keyHash must already be registered with the VRFCoordinator, and
   * @dev the _fee must exceed the fee specified during registration of the
   * @dev _keyHash.
   *
   * @dev The _seed parameter is vestigial, and is kept only for API
   * @dev compatibility with older versions. It can't *hurt* to mix in some of
   * @dev your own randomness, here, but it's not necessary because the VRF
   * @dev oracle will mix the hash of the block containing your request into the
   * @dev VRF seed it ultimately uses.
   *
   * @param _keyHash ID of public key against which randomness is generated
   * @param _fee The amount of LINK to send with the request
   *
   * @return requestId unique ID for this request
   *
   * @dev The returned requestId can be used to distinguish responses to
   * @dev concurrent requests. It is passed as the first argument to
   * @dev fulfillRandomness.
   */
  function requestRandomness(bytes32 _keyHash, uint256 _fee) internal returns (bytes32 requestId) {
    LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PLACEHOLDER));
    // This is the seed passed to VRFCoordinator. The oracle will mix this with
    // the hash of the block containing this request to obtain the seed/input
    // which is finally passed to the VRF cryptographic machinery.
    uint256 vRFSeed = makeVRFInputSeed(_keyHash, USER_SEED_PLACEHOLDER, address(this), nonces[_keyHash]);
    // nonces[_keyHash] must stay in sync with
    // VRFCoordinator.nonces[_keyHash][this], which was incremented by the above
    // successful LINK.transferAndCall (in VRFCoordinator.randomnessRequest).
    // This provides protection against the user repeating their input seed,
    // which would result in a predictable/duplicate output, if multiple such
    // requests appeared in the same block.
    nonces[_keyHash] = nonces[_keyHash] + 1;
    return makeRequestId(_keyHash, vRFSeed);
  }

  LinkTokenInterface internal immutable LINK;
  address private immutable vrfCoordinator;

  // Nonces for each VRF key from which randomness has been requested.
  //
  // Must stay in sync with VRFCoordinator[_keyHash][this]
  mapping(bytes32 => uint256) /* keyHash */ /* nonce */
    private nonces;

  /**
   * @param _vrfCoordinator address of VRFCoordinator contract
   * @param _link address of LINK token contract
   *
   * @dev https://docs.chain.link/docs/link-token-contracts
   */
  constructor(address _vrfCoordinator, address _link) {
    vrfCoordinator = _vrfCoordinator;
    LINK = LinkTokenInterface(_link);
  }

  // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF
  // proof. rawFulfillRandomness then calls fulfillRandomness, after validating
  // the origin of the call
  function rawFulfillRandomness(bytes32 requestId, uint256 randomness) external {
    require(msg.sender == vrfCoordinator, "Only VRFCoordinator can fulfill");
    fulfillRandomness(requestId, randomness);
  }
}

Settings
{
  "remappings": [],
  "optimizer": {
    "enabled": false,
    "runs": 200
  },
  "evmVersion": "london",
  "libraries": {},
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_VRFCoordinator","type":"address"},{"internalType":"address","name":"_LinkToken","type":"address"},{"internalType":"bytes32","name":"_keyHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"randomNumbers","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"},{"internalType":"uint256","name":"randomness","type":"uint256"}],"name":"rawFulfillRandomness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"requestRandomNumber","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"}]

60c060405234801561001057600080fd5b50604051610a3a380380610a3a83398181016040528101906100329190610153565b82828173ffffffffffffffffffffffffffffffffffffffff1660a08173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1681525050505080600181905550655af3107a40006002819055505050506101a6565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100ea826100bf565b9050919050565b6100fa816100df565b811461010557600080fd5b50565b600081519050610117816100f1565b92915050565b6000819050919050565b6101308161011d565b811461013b57600080fd5b50565b60008151905061014d81610127565b92915050565b60008060006060848603121561016c5761016b6100ba565b5b600061017a86828701610108565b935050602061018b86828701610108565b925050604061019c8682870161013e565b9150509250925092565b60805160a0516108686101d26000396000818161011901526101f9015260006101bd01526108686000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80635257cd90146100515780638678a7b21461008157806394985ddd1461009f578063ddca3f43146100bb575b600080fd5b61006b600480360381019061006691906103e0565b6100d9565b604051610078919061041c565b60405180910390f35b6100896100fd565b6040516100969190610450565b60405180910390f35b6100b960048036038101906100b49190610497565b610117565b005b6100c36101b3565b6040516100d0919061041c565b60405180910390f35b600381815481106100e957600080fd5b906000526020600020016000915090505481565b60008061010e6001546002546101b9565b90508091505090565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161019c90610534565b60405180910390fd5b6101af8282610309565b5050565b60025481565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16634000aea07f00000000000000000000000000000000000000000000000000000000000000008486600060405160200161022d929190610554565b6040516020818303038152906040526040518463ffffffff1660e01b815260040161025a93929190610657565b6020604051808303816000875af1158015610279573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061029d91906106cd565b5060006102bf8460003060008089815260200190815260200160002054610336565b90506001600080868152602001908152602001600020546102e09190610729565b600080868152602001908152602001600020819055506103008482610372565b91505092915050565b60038190806001815401808255809150506001900390600052602060002001600090919091909150555050565b60008484848460405160200161034f949392919061077f565b6040516020818303038152906040528051906020012060001c9050949350505050565b60008282604051602001610387929190610806565b60405160208183030381529060405280519060200120905092915050565b600080fd5b6000819050919050565b6103bd816103aa565b81146103c857600080fd5b50565b6000813590506103da816103b4565b92915050565b6000602082840312156103f6576103f56103a5565b5b6000610404848285016103cb565b91505092915050565b610416816103aa565b82525050565b6000602082019050610431600083018461040d565b92915050565b6000819050919050565b61044a81610437565b82525050565b60006020820190506104656000830184610441565b92915050565b61047481610437565b811461047f57600080fd5b50565b6000813590506104918161046b565b92915050565b600080604083850312156104ae576104ad6103a5565b5b60006104bc85828601610482565b92505060206104cd858286016103cb565b9150509250929050565b600082825260208201905092915050565b7f4f6e6c7920565246436f6f7264696e61746f722063616e2066756c66696c6c00600082015250565b600061051e601f836104d7565b9150610529826104e8565b602082019050919050565b6000602082019050818103600083015261054d81610511565b9050919050565b60006040820190506105696000830185610441565b610576602083018461040d565b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105a88261057d565b9050919050565b6105b88161059d565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b838110156105f85780820151818401526020810190506105dd565b83811115610607576000848401525b50505050565b6000601f19601f8301169050919050565b6000610629826105be565b61063381856105c9565b93506106438185602086016105da565b61064c8161060d565b840191505092915050565b600060608201905061066c60008301866105af565b610679602083018561040d565b818103604083015261068b818461061e565b9050949350505050565b60008115159050919050565b6106aa81610695565b81146106b557600080fd5b50565b6000815190506106c7816106a1565b92915050565b6000602082840312156106e3576106e26103a5565b5b60006106f1848285016106b8565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610734826103aa565b915061073f836103aa565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610774576107736106fa565b5b828201905092915050565b60006080820190506107946000830187610441565b6107a1602083018661040d565b6107ae60408301856105af565b6107bb606083018461040d565b95945050505050565b6000819050919050565b6107df6107da82610437565b6107c4565b82525050565b6000819050919050565b6108006107fb826103aa565b6107e5565b82525050565b600061081282856107ce565b60208201915061082282846107ef565b602082019150819050939250505056fea264697066735822122048535ac063fab40ff525eb34b84dbf46fb9210634dec2852f916f75a18b2ab9164736f6c634300080a00330000000000000000000000008c7382f9d8f56b33781fe506e897a4f1e2d17255000000000000000000000000326c977e6efc84e512bb9c30f76e30c160ed06fb6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000008c7382f9d8f56b33781fe506e897a4f1e2d17255000000000000000000000000326c977e6efc84e512bb9c30f76e30c160ed06fb6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4

-----Decoded View---------------
Arg [0] : _VRFCoordinator (address): 0x8c7382f9d8f56b33781fe506e897a4f1e2d17255
Arg [1] : _LinkToken (address): 0x326c977e6efc84e512bb9c30f76e30c160ed06fb
Arg [2] : _keyHash (bytes32): 0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000008c7382f9d8f56b33781fe506e897a4f1e2d17255
Arg [1] : 000000000000000000000000326c977e6efc84e512bb9c30f76e30c160ed06fb
Arg [2] : 6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading