Source Code
Overview
ETH Balance
0.01 ETH
Token Holdings
More Info
ContractCreator
Multichain Info
N/A
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
2844674 | 8 days ago | 0.01 ETH |
Loading...
Loading
Contract Name:
MyToken
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
No with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; contract MyToken{ IERC20 public token; IERC721 public nftContract; // NFT合约地址 constructor(address _tokenAddress, address _nftAddress) { token = IERC20(_tokenAddress); nftContract = IERC721(_nftAddress); } function transferOut(address payable _to, uint256 amount, uint256 _tokenId) external payable { require(token.balanceOf(address(this)) > amount, "lock of balance"); // eth主币 _to.transfer(amount); // erc20 token.transfer(_to, amount); // nft nftContract.transferFrom(address(this), _to, _tokenId); } // 收到eth事件,记录amount和gas event Log(uint amount, uint gas); // receive方法,接收eth时被触发 receive() external payable{ emit Log(msg.value, gasleft()); } // 返回合约ETH余额 function getBalance() view public returns(uint) { return address(this).balance; } // 将NFT转移到合约中 function transferNFTToContract(address _owner, uint256 _tokenId) public { nftContract.transferFrom(_owner, address(this), _tokenId); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.20; import {IERC165} from "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC-721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC-721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or * {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the address zero. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
{ "optimizer": { "enabled": false, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "remappings": [] }
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_nftAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"gas","type":"uint256"}],"name":"Log","type":"event"},{"inputs":[],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftContract","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"transferNFTToContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"transferOut","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561000f575f80fd5b50604051610a54380380610a5483398181016040528101906100319190610115565b815f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050610153565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100e4826100bb565b9050919050565b6100f4816100da565b81146100fe575f80fd5b50565b5f8151905061010f816100eb565b92915050565b5f806040838503121561012b5761012a6100b7565b5b5f61013885828601610101565b925050602061014985828601610101565b9150509250929050565b6108f4806101605f395ff3fe60806040526004361061004d575f3560e01c806312065fe014610091578063814785eb146100bb578063a90dceab146100d7578063d56d229d146100ff578063fc0c546a146101295761008d565b3661008d577fbd0faddf87043dd749c1b9d4dca8a12589b8cb5e2106832111ce23f219b14367345a604051610083929190610490565b60405180910390a1005b5f80fd5b34801561009c575f80fd5b506100a5610153565b6040516100b291906104b7565b60405180910390f35b6100d560048036038101906100d09190610558565b61015a565b005b3480156100e2575f80fd5b506100fd60048036038101906100f891906105e3565b6103a1565b005b34801561010a575f80fd5b50610113610430565b604051610120919061067c565b60405180910390f35b348015610134575f80fd5b5061013d610455565b60405161014a91906106b5565b60405180910390f35b5f47905090565b815f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016101b391906106dd565b602060405180830381865afa1580156101ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101f2919061070a565b11610232576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102299061078f565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc8390811502906040515f60405180830381858888f19350505050158015610275573d5f803e3d5ffd5b505f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb84846040518363ffffffff1660e01b81526004016102d09291906107cd565b6020604051808303815f875af11580156102ec573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103109190610829565b5060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3085846040518463ffffffff1660e01b815260040161036f93929190610854565b5f604051808303815f87803b158015610386575f80fd5b505af1158015610398573d5f803e3d5ffd5b50505050505050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd8330846040518463ffffffff1660e01b81526004016103ff93929190610889565b5f604051808303815f87803b158015610416575f80fd5b505af1158015610428573d5f803e3d5ffd5b505050505050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f819050919050565b61048a81610478565b82525050565b5f6040820190506104a35f830185610481565b6104b06020830184610481565b9392505050565b5f6020820190506104ca5f830184610481565b92915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6104fd826104d4565b9050919050565b61050d816104f3565b8114610517575f80fd5b50565b5f8135905061052881610504565b92915050565b61053781610478565b8114610541575f80fd5b50565b5f813590506105528161052e565b92915050565b5f805f6060848603121561056f5761056e6104d0565b5b5f61057c8682870161051a565b935050602061058d86828701610544565b925050604061059e86828701610544565b9150509250925092565b5f6105b2826104d4565b9050919050565b6105c2816105a8565b81146105cc575f80fd5b50565b5f813590506105dd816105b9565b92915050565b5f80604083850312156105f9576105f86104d0565b5b5f610606858286016105cf565b925050602061061785828601610544565b9150509250929050565b5f819050919050565b5f61064461063f61063a846104d4565b610621565b6104d4565b9050919050565b5f6106558261062a565b9050919050565b5f6106668261064b565b9050919050565b6106768161065c565b82525050565b5f60208201905061068f5f83018461066d565b92915050565b5f61069f8261064b565b9050919050565b6106af81610695565b82525050565b5f6020820190506106c85f8301846106a6565b92915050565b6106d7816105a8565b82525050565b5f6020820190506106f05f8301846106ce565b92915050565b5f815190506107048161052e565b92915050565b5f6020828403121561071f5761071e6104d0565b5b5f61072c848285016106f6565b91505092915050565b5f82825260208201905092915050565b7f6c6f636b206f662062616c616e636500000000000000000000000000000000005f82015250565b5f610779600f83610735565b915061078482610745565b602082019050919050565b5f6020820190508181035f8301526107a68161076d565b9050919050565b5f6107b78261064b565b9050919050565b6107c7816107ad565b82525050565b5f6040820190506107e05f8301856107be565b6107ed6020830184610481565b9392505050565b5f8115159050919050565b610808816107f4565b8114610812575f80fd5b50565b5f81519050610823816107ff565b92915050565b5f6020828403121561083e5761083d6104d0565b5b5f61084b84828501610815565b91505092915050565b5f6060820190506108675f8301866106ce565b61087460208301856107be565b6108816040830184610481565b949350505050565b5f60608201905061089c5f8301866106ce565b6108a960208301856106ce565b6108b66040830184610481565b94935050505056fea264697066735822122099f683ebd8894d546a5ca6c057350ad818b1722e1563adceea2958205a7c4add64736f6c63430008140033000000000000000000000000a1c98210516c30aa4e6a9e79265e87151d55e48800000000000000000000000043c651e840d56ee0b00ad287748d79b06cf63571
Deployed Bytecode
0x60806040526004361061004d575f3560e01c806312065fe014610091578063814785eb146100bb578063a90dceab146100d7578063d56d229d146100ff578063fc0c546a146101295761008d565b3661008d577fbd0faddf87043dd749c1b9d4dca8a12589b8cb5e2106832111ce23f219b14367345a604051610083929190610490565b60405180910390a1005b5f80fd5b34801561009c575f80fd5b506100a5610153565b6040516100b291906104b7565b60405180910390f35b6100d560048036038101906100d09190610558565b61015a565b005b3480156100e2575f80fd5b506100fd60048036038101906100f891906105e3565b6103a1565b005b34801561010a575f80fd5b50610113610430565b604051610120919061067c565b60405180910390f35b348015610134575f80fd5b5061013d610455565b60405161014a91906106b5565b60405180910390f35b5f47905090565b815f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b81526004016101b391906106dd565b602060405180830381865afa1580156101ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101f2919061070a565b11610232576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102299061078f565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc8390811502906040515f60405180830381858888f19350505050158015610275573d5f803e3d5ffd5b505f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb84846040518363ffffffff1660e01b81526004016102d09291906107cd565b6020604051808303815f875af11580156102ec573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103109190610829565b5060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3085846040518463ffffffff1660e01b815260040161036f93929190610854565b5f604051808303815f87803b158015610386575f80fd5b505af1158015610398573d5f803e3d5ffd5b50505050505050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd8330846040518463ffffffff1660e01b81526004016103ff93929190610889565b5f604051808303815f87803b158015610416575f80fd5b505af1158015610428573d5f803e3d5ffd5b505050505050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f819050919050565b61048a81610478565b82525050565b5f6040820190506104a35f830185610481565b6104b06020830184610481565b9392505050565b5f6020820190506104ca5f830184610481565b92915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6104fd826104d4565b9050919050565b61050d816104f3565b8114610517575f80fd5b50565b5f8135905061052881610504565b92915050565b61053781610478565b8114610541575f80fd5b50565b5f813590506105528161052e565b92915050565b5f805f6060848603121561056f5761056e6104d0565b5b5f61057c8682870161051a565b935050602061058d86828701610544565b925050604061059e86828701610544565b9150509250925092565b5f6105b2826104d4565b9050919050565b6105c2816105a8565b81146105cc575f80fd5b50565b5f813590506105dd816105b9565b92915050565b5f80604083850312156105f9576105f86104d0565b5b5f610606858286016105cf565b925050602061061785828601610544565b9150509250929050565b5f819050919050565b5f61064461063f61063a846104d4565b610621565b6104d4565b9050919050565b5f6106558261062a565b9050919050565b5f6106668261064b565b9050919050565b6106768161065c565b82525050565b5f60208201905061068f5f83018461066d565b92915050565b5f61069f8261064b565b9050919050565b6106af81610695565b82525050565b5f6020820190506106c85f8301846106a6565b92915050565b6106d7816105a8565b82525050565b5f6020820190506106f05f8301846106ce565b92915050565b5f815190506107048161052e565b92915050565b5f6020828403121561071f5761071e6104d0565b5b5f61072c848285016106f6565b91505092915050565b5f82825260208201905092915050565b7f6c6f636b206f662062616c616e636500000000000000000000000000000000005f82015250565b5f610779600f83610735565b915061078482610745565b602082019050919050565b5f6020820190508181035f8301526107a68161076d565b9050919050565b5f6107b78261064b565b9050919050565b6107c7816107ad565b82525050565b5f6040820190506107e05f8301856107be565b6107ed6020830184610481565b9392505050565b5f8115159050919050565b610808816107f4565b8114610812575f80fd5b50565b5f81519050610823816107ff565b92915050565b5f6020828403121561083e5761083d6104d0565b5b5f61084b84828501610815565b91505092915050565b5f6060820190506108675f8301866106ce565b61087460208301856107be565b6108816040830184610481565b949350505050565b5f60608201905061089c5f8301866106ce565b6108a960208301856106ce565b6108b66040830184610481565b94935050505056fea264697066735822122099f683ebd8894d546a5ca6c057350ad818b1722e1563adceea2958205a7c4add64736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a1c98210516c30aa4e6a9e79265e87151d55e48800000000000000000000000043c651e840d56ee0b00ad287748d79b06cf63571
-----Decoded View---------------
Arg [0] : _tokenAddress (address): 0xA1c98210516c30aA4E6a9e79265e87151D55e488
Arg [1] : _nftAddress (address): 0x43C651e840D56eE0B00AD287748D79B06Cf63571
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000a1c98210516c30aa4e6a9e79265e87151d55e488
Arg [1] : 00000000000000000000000043c651e840d56ee0b00ad287748d79b06cf63571
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.