Source Code
Overview
ETH Balance
0.005 ETH
More Info
ContractCreator
Multichain Info
N/A
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Method | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|---|
Transfer | 6474113 | 225 days ago | 0.005 ETH |
Loading...
Loading
Contract Name:
Bank
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol"; contract Bank is AutomationCompatibleInterface { address public owner; uint256 public threshold; mapping(address => uint256) public balances; event Deposited(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); constructor(uint256 _threshold) { owner = msg.sender; threshold = _threshold; } function deposit() public payable { require(msg.value > 0, "Deposit must be greater than 0"); balances[msg.sender] += msg.value; emit Deposited(msg.sender, msg.value); } function getBalance() external view returns (uint256) { return address(this).balance; } function setThreshold(uint256 _newThreshold) external { require(msg.sender == owner, "Only owner can set the threshold"); threshold = _newThreshold; } // checkUpKeep():在链下间隔执行调用该函数, 该方法返回一个布尔值,告诉网络是否需要自动化执行。 function checkUpkeep( bytes calldata /* checkData */ ) external view override returns (bool shouldTransferFunds, bytes memory /* performData */) { shouldTransferFunds = (address(this).balance > threshold); } // performUpKeep():这个方法接受从checkUpKeep()方法返回的信息作为参数。Chainlink Automation 会触发对它的调用。函数应该先进行一些检查,再执行链上其他计算。 function performUpkeep(bytes calldata /* performData */) external override { if (address(this).balance > threshold) { uint256 halfBalance = address(this).balance / 2; // payable(owner).transfer(halfBalance); (bool success, ) = payable(owner).call{value: halfBalance}(""); require(success, "Transfer failed"); } } function withdraw() external { require(msg.sender == owner, "Only owner can withdraw"); payable(msg.sender).transfer(address(this).balance); // 转账给调用者 } // Receive function to accept direct Ether transfers receive() external payable { deposit(); } // Fallback function to handle any calls to non-existent functions fallback() external payable { deposit(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {AutomationBase} from "./AutomationBase.sol"; import {AutomationCompatibleInterface} from "./interfaces/AutomationCompatibleInterface.sol"; abstract contract AutomationCompatible is AutomationBase, AutomationCompatibleInterface {}
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract AutomationBase { error OnlySimulatedBackend(); /** * @notice method that allows it to be simulated via eth_call by checking that * the sender is the zero address. */ function _preventExecution() internal view { // solhint-disable-next-line avoid-tx-origin if (tx.origin != address(0) && tx.origin != address(0x1111111111111111111111111111111111111111)) { revert OnlySimulatedBackend(); } } /** * @notice modifier that allows it to be simulated via eth_call by checking * that the sender is the zero address. */ modifier cannotExecute() { _preventExecution(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // solhint-disable-next-line interface-starts-with-i interface AutomationCompatibleInterface { /** * @notice method that is simulated by the keepers to see if any work actually * needs to be performed. This method does does not actually need to be * executable, and since it is only ever simulated it can consume lots of gas. * @dev To ensure that it is never called, you may want to add the * cannotExecute modifier from KeeperBase to your implementation of this * method. * @param checkData specified in the upkeep registration so it is always the * same for a registered upkeep. This can easily be broken down into specific * arguments using `abi.decode`, so multiple upkeeps can be registered on the * same contract and easily differentiated by the contract. * @return upkeepNeeded boolean to indicate whether the keeper should call * performUpkeep or not. * @return performData bytes that the keeper should call performUpkeep with, if * upkeep is needed. If you would like to encode data to decode later, try * `abi.encode`. */ function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData); /** * @notice method that is actually executed by the keepers, via the registry. * The data returned by the checkUpkeep simulation will be passed into * this method to actually be executed. * @dev The input to this method should not be trusted, and the caller of the * method should not even be restricted to any single registry. Anyone should * be able call it, and the input should be validated, there is no guarantee * that the data passed in is the performData returned from checkUpkeep. This * could happen due to malicious keepers, racing keepers, or simply a state * change while the performUpkeep transaction is waiting for confirmation. * Always validate the data passed in. * @param performData is the data which was passed back from the checkData * simulation. If it is encoded, it can easily be decoded into other types by * calling `abi.decode`. This data should not be trusted, and should be * validated against the contract's current state. */ function performUpkeep(bytes calldata performData) external; }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "@chainlink/contracts/=lib/chainlink/contracts/", "chainlink/=lib/chainlink/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": false, "libraries": {} }
Contract ABI
API[{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"shouldTransferFunds","type":"bool"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newThreshold","type":"uint256"}],"name":"setThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"threshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561001057600080fd5b5060405161061c38038061061c83398101604081905261002f91610049565b600080546001600160a01b03191633179055600155610062565b60006020828403121561005b57600080fd5b5051919050565b6105ab806100716000396000f3fe60806040526004361061008a5760003560e01c80634585e33b116100595780634585e33b1461011b5780636e04ff0d1461013b5780638da5cb5b14610171578063960bfe04146101a9578063d0e30db01461009957610099565b806312065fe0146100a157806327e235e3146100c35780633ccfd60b146100f057806342cde4e81461010557610099565b36610099576100976101c9565b005b6100976101c9565b3480156100ad57600080fd5b50475b6040519081526020015b60405180910390f35b3480156100cf57600080fd5b506100b06100de366004610419565b60026020526000908152604090205481565b3480156100fc57600080fd5b50610097610279565b34801561011157600080fd5b506100b060015481565b34801561012757600080fd5b50610097610136366004610449565b610302565b34801561014757600080fd5b50610163610156366004610449565b5050600154471190606090565b6040516100ba9291906104bb565b34801561017d57600080fd5b50600054610191906001600160a01b031681565b6040516001600160a01b0390911681526020016100ba565b3480156101b557600080fd5b506100976101c4366004610513565b6103ba565b6000341161021e5760405162461bcd60e51b815260206004820152601e60248201527f4465706f736974206d7573742062652067726561746572207468616e2030000060448201526064015b60405180910390fd5b336000908152600260205260408120805434929061023d90849061052c565b909155505060405134815233907f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c49060200160405180910390a2565b6000546001600160a01b031633146102d35760405162461bcd60e51b815260206004820152601760248201527f4f6e6c79206f776e65722063616e2077697468647261770000000000000000006044820152606401610215565b60405133904780156108fc02916000818181858888f193505050501580156102ff573d6000803e3d6000fd5b50565b6001544711156103b6576000610319600247610553565b6000805460405192935090916001600160a01b039091169083908381818185875af1925050503d806000811461036b576040519150601f19603f3d011682016040523d82523d6000602084013e610370565b606091505b50509050806103b35760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610215565b50505b5050565b6000546001600160a01b031633146104145760405162461bcd60e51b815260206004820181905260248201527f4f6e6c79206f776e65722063616e2073657420746865207468726573686f6c646044820152606401610215565b600155565b60006020828403121561042b57600080fd5b81356001600160a01b038116811461044257600080fd5b9392505050565b6000806020838503121561045c57600080fd5b823567ffffffffffffffff8082111561047457600080fd5b818501915085601f83011261048857600080fd5b81358181111561049757600080fd5b8660208285010111156104a957600080fd5b60209290920196919550909350505050565b821515815260006020604081840152835180604085015260005b818110156104f1578581018301518582016060015282016104d5565b506000606082860101526060601f19601f830116850101925050509392505050565b60006020828403121561052557600080fd5b5035919050565b8082018082111561054d57634e487b7160e01b600052601160045260246000fd5b92915050565b60008261057057634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220a8664fb0c1f5576e7586effbb5579ede0fa1791627d842291be251739cd181a864736f6c63430008140033000000000000000000000000000000000000000000000000001c6bf526340000
Deployed Bytecode
0x60806040526004361061008a5760003560e01c80634585e33b116100595780634585e33b1461011b5780636e04ff0d1461013b5780638da5cb5b14610171578063960bfe04146101a9578063d0e30db01461009957610099565b806312065fe0146100a157806327e235e3146100c35780633ccfd60b146100f057806342cde4e81461010557610099565b36610099576100976101c9565b005b6100976101c9565b3480156100ad57600080fd5b50475b6040519081526020015b60405180910390f35b3480156100cf57600080fd5b506100b06100de366004610419565b60026020526000908152604090205481565b3480156100fc57600080fd5b50610097610279565b34801561011157600080fd5b506100b060015481565b34801561012757600080fd5b50610097610136366004610449565b610302565b34801561014757600080fd5b50610163610156366004610449565b5050600154471190606090565b6040516100ba9291906104bb565b34801561017d57600080fd5b50600054610191906001600160a01b031681565b6040516001600160a01b0390911681526020016100ba565b3480156101b557600080fd5b506100976101c4366004610513565b6103ba565b6000341161021e5760405162461bcd60e51b815260206004820152601e60248201527f4465706f736974206d7573742062652067726561746572207468616e2030000060448201526064015b60405180910390fd5b336000908152600260205260408120805434929061023d90849061052c565b909155505060405134815233907f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c49060200160405180910390a2565b6000546001600160a01b031633146102d35760405162461bcd60e51b815260206004820152601760248201527f4f6e6c79206f776e65722063616e2077697468647261770000000000000000006044820152606401610215565b60405133904780156108fc02916000818181858888f193505050501580156102ff573d6000803e3d6000fd5b50565b6001544711156103b6576000610319600247610553565b6000805460405192935090916001600160a01b039091169083908381818185875af1925050503d806000811461036b576040519150601f19603f3d011682016040523d82523d6000602084013e610370565b606091505b50509050806103b35760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610215565b50505b5050565b6000546001600160a01b031633146104145760405162461bcd60e51b815260206004820181905260248201527f4f6e6c79206f776e65722063616e2073657420746865207468726573686f6c646044820152606401610215565b600155565b60006020828403121561042b57600080fd5b81356001600160a01b038116811461044257600080fd5b9392505050565b6000806020838503121561045c57600080fd5b823567ffffffffffffffff8082111561047457600080fd5b818501915085601f83011261048857600080fd5b81358181111561049757600080fd5b8660208285010111156104a957600080fd5b60209290920196919550909350505050565b821515815260006020604081840152835180604085015260005b818110156104f1578581018301518582016060015282016104d5565b506000606082860101526060601f19601f830116850101925050509392505050565b60006020828403121561052557600080fd5b5035919050565b8082018082111561054d57634e487b7160e01b600052601160045260246000fd5b92915050565b60008261057057634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220a8664fb0c1f5576e7586effbb5579ede0fa1791627d842291be251739cd181a864736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000001c6bf526340000
-----Decoded View---------------
Arg [0] : _threshold (uint256): 8000000000000000
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000000000000000000000000000001c6bf526340000
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.