Overview
GLMR Balance
0 GLMR
GLMR Value
$0.00More Info
Private Name Tags
ContractCreator:
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0x60806040 | 2806946 | 428 days ago | IN | Create: NftMarketplace | 0 GLMR | 0.06846149 |
Loading...
Loading
Contract Name:
NftMarketplace
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
No with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// Inspired by https://github.com/PatrickAlphaC/hardhat-nft-marketplace-fcc/blob/main/contracts/NftMarketplace.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; error NotOwner(); error PriceMustBeAboveZero(); error NotApprovedForMarketplace(); error PriceNotMet(address nftAddress, uint256 tokenId, uint256 price); contract NftMarketplace is ReentrancyGuard { struct Listing { uint256 price; address seller; } // Map the NFT address to the listing information mapping(address => mapping(uint256 => Listing)) private s_listings; event NftListed( address indexed seller, address indexed nftAddress, uint256 indexed tokenId, uint256 price ); event NftPurchased( address indexed buyer, address indexed nftAddress, uint256 indexed tokenId, uint256 price ); modifier isOwner( address nftAddress, uint256 tokenId, address spender ) { // Ensure that only the owner of an NFT can list it IERC721 nft = IERC721(nftAddress); address owner = nft.ownerOf(tokenId); if (spender != owner) { revert NotOwner(); } _; } function listNft( address nftAddress, uint256 tokenId, uint256 price ) external isOwner(nftAddress, tokenId, msg.sender) { if (price <= 0) { revert PriceMustBeAboveZero(); } IERC721 nft = IERC721(nftAddress); // Make sure that the marketplace has been approved to transfer the NFT if (nft.getApproved(tokenId) != address(this)) { revert NotApprovedForMarketplace(); } // Save the NFT to state s_listings[nftAddress][tokenId] = Listing(price, msg.sender); emit NftListed(msg.sender, nftAddress, tokenId, price); } function purchaseNft(address nftAddress, uint256 tokenId) external payable nonReentrant { Listing memory listedItem = s_listings[nftAddress][tokenId]; // Make sure the payment received is not less than the listing price if (msg.value < listedItem.price) { revert PriceNotMet(nftAddress, tokenId, listedItem.price); } // Remove the NFT from state delete (s_listings[nftAddress][tokenId]); // Transfer the NFT to the buyer IERC721(nftAddress).safeTransferFrom(listedItem.seller, msg.sender, tokenId); emit NftPurchased(msg.sender, nftAddress, tokenId, listedItem.price); // Send the payment to the seller (bool success, ) = payable(listedItem.seller).call{value: msg.value}(""); require(success, "Transfer failed"); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * 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[EIP 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 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 ERC721 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 ERC721 * 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 caller. * * 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 v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
{ "remappings": [], "optimizer": { "enabled": false, "runs": 200 }, "evmVersion": "london", "libraries": {}, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"name":"NotApprovedForMarketplace","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"PriceMustBeAboveZero","type":"error"},{"inputs":[{"internalType":"address","name":"nftAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"name":"PriceNotMet","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"nftAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"}],"name":"NftListed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"nftAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"}],"name":"NftPurchased","type":"event"},{"inputs":[{"internalType":"address","name":"nftAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"name":"listNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"purchaseNft","outputs":[],"stateMutability":"payable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b506001600081905550610ac3806100286000396000f3fe6080604052600436106100295760003560e01c80635a0b17b01461002e578063c922b17c1461004a575b600080fd5b610048600480360381019061004391906107e2565b610073565b005b34801561005657600080fd5b50610071600480360381019061006c9190610822565b6103a8565b005b61007b6106f0565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838152602001908152602001600020604051806040016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815250509050806000015134101561018b57828282600001516040517f7c93456500000000000000000000000000000000000000000000000000000000815260040161018293929190610893565b60405180910390fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550508273ffffffffffffffffffffffffffffffffffffffff166342842e0e826020015133856040518463ffffffff1660e01b815260040161024e939291906108ca565b600060405180830381600087803b15801561026857600080fd5b505af115801561027c573d6000803e3d6000fd5b50505050818373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fa74de28e54787a960cbaa9b7895f35de55208685634515d5c36981a05410b3e684600001516040516102e29190610901565b60405180910390a46000816020015173ffffffffffffffffffffffffffffffffffffffff16346040516103149061094d565b60006040518083038185875af1925050503d8060008114610351576040519150601f19603f3d011682016040523d82523d6000602084013e610356565b606091505b505090508061039a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610391906109bf565b60405180910390fd5b50506103a461073f565b5050565b828233600083905060008173ffffffffffffffffffffffffffffffffffffffff16636352211e856040518263ffffffff1660e01b81526004016103eb9190610901565b602060405180830381865afa158015610408573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061042c91906109f4565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614610493576040517f30cd747100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600086116104cd576040517fe1abbfc500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008890503073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1663081812fc8a6040518263ffffffff1660e01b81526004016105229190610901565b602060405180830381865afa15801561053f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056391906109f4565b73ffffffffffffffffffffffffffffffffffffffff16146105b0576040517f4be3a2c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180604001604052808881526020013373ffffffffffffffffffffffffffffffffffffffff16815250600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a81526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550905050878973ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f061b06d224d66454e036e75de172ad87cb7d7f29ee8b7346ca2b48ba0da280428a6040516106dd9190610901565b60405180910390a4505050505050505050565b600260005403610735576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161072c90610a6d565b60405180910390fd5b6002600081905550565b6001600081905550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006107798261074e565b9050919050565b6107898161076e565b811461079457600080fd5b50565b6000813590506107a681610780565b92915050565b6000819050919050565b6107bf816107ac565b81146107ca57600080fd5b50565b6000813590506107dc816107b6565b92915050565b600080604083850312156107f9576107f8610749565b5b600061080785828601610797565b9250506020610818858286016107cd565b9150509250929050565b60008060006060848603121561083b5761083a610749565b5b600061084986828701610797565b935050602061085a868287016107cd565b925050604061086b868287016107cd565b9150509250925092565b61087e8161076e565b82525050565b61088d816107ac565b82525050565b60006060820190506108a86000830186610875565b6108b56020830185610884565b6108c26040830184610884565b949350505050565b60006060820190506108df6000830186610875565b6108ec6020830185610875565b6108f96040830184610884565b949350505050565b60006020820190506109166000830184610884565b92915050565b600081905092915050565b50565b600061093760008361091c565b915061094282610927565b600082019050919050565b60006109588261092a565b9150819050919050565b600082825260208201905092915050565b7f5472616e73666572206661696c65640000000000000000000000000000000000600082015250565b60006109a9600f83610962565b91506109b482610973565b602082019050919050565b600060208201905081810360008301526109d88161099c565b9050919050565b6000815190506109ee81610780565b92915050565b600060208284031215610a0a57610a09610749565b5b6000610a18848285016109df565b91505092915050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000610a57601f83610962565b9150610a6282610a21565b602082019050919050565b60006020820190508181036000830152610a8681610a4a565b905091905056fea26469706673582212209d4259332865a4705a14637bd9479c8c8dcf5caf32699190876664bcad3dce5d64736f6c63430008110033
Deployed Bytecode
0x6080604052600436106100295760003560e01c80635a0b17b01461002e578063c922b17c1461004a575b600080fd5b610048600480360381019061004391906107e2565b610073565b005b34801561005657600080fd5b50610071600480360381019061006c9190610822565b6103a8565b005b61007b6106f0565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838152602001908152602001600020604051806040016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815250509050806000015134101561018b57828282600001516040517f7c93456500000000000000000000000000000000000000000000000000000000815260040161018293929190610893565b60405180910390fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905550508273ffffffffffffffffffffffffffffffffffffffff166342842e0e826020015133856040518463ffffffff1660e01b815260040161024e939291906108ca565b600060405180830381600087803b15801561026857600080fd5b505af115801561027c573d6000803e3d6000fd5b50505050818373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fa74de28e54787a960cbaa9b7895f35de55208685634515d5c36981a05410b3e684600001516040516102e29190610901565b60405180910390a46000816020015173ffffffffffffffffffffffffffffffffffffffff16346040516103149061094d565b60006040518083038185875af1925050503d8060008114610351576040519150601f19603f3d011682016040523d82523d6000602084013e610356565b606091505b505090508061039a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610391906109bf565b60405180910390fd5b50506103a461073f565b5050565b828233600083905060008173ffffffffffffffffffffffffffffffffffffffff16636352211e856040518263ffffffff1660e01b81526004016103eb9190610901565b602060405180830381865afa158015610408573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061042c91906109f4565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614610493576040517f30cd747100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600086116104cd576040517fe1abbfc500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008890503073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1663081812fc8a6040518263ffffffff1660e01b81526004016105229190610901565b602060405180830381865afa15801561053f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056391906109f4565b73ffffffffffffffffffffffffffffffffffffffff16146105b0576040517f4be3a2c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180604001604052808881526020013373ffffffffffffffffffffffffffffffffffffffff16815250600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a81526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550905050878973ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f061b06d224d66454e036e75de172ad87cb7d7f29ee8b7346ca2b48ba0da280428a6040516106dd9190610901565b60405180910390a4505050505050505050565b600260005403610735576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161072c90610a6d565b60405180910390fd5b6002600081905550565b6001600081905550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006107798261074e565b9050919050565b6107898161076e565b811461079457600080fd5b50565b6000813590506107a681610780565b92915050565b6000819050919050565b6107bf816107ac565b81146107ca57600080fd5b50565b6000813590506107dc816107b6565b92915050565b600080604083850312156107f9576107f8610749565b5b600061080785828601610797565b9250506020610818858286016107cd565b9150509250929050565b60008060006060848603121561083b5761083a610749565b5b600061084986828701610797565b935050602061085a868287016107cd565b925050604061086b868287016107cd565b9150509250925092565b61087e8161076e565b82525050565b61088d816107ac565b82525050565b60006060820190506108a86000830186610875565b6108b56020830185610884565b6108c26040830184610884565b949350505050565b60006060820190506108df6000830186610875565b6108ec6020830185610875565b6108f96040830184610884565b949350505050565b60006020820190506109166000830184610884565b92915050565b600081905092915050565b50565b600061093760008361091c565b915061094282610927565b600082019050919050565b60006109588261092a565b9150819050919050565b600082825260208201905092915050565b7f5472616e73666572206661696c65640000000000000000000000000000000000600082015250565b60006109a9600f83610962565b91506109b482610973565b602082019050919050565b600060208201905081810360008301526109d88161099c565b9050919050565b6000815190506109ee81610780565b92915050565b600060208284031215610a0a57610a09610749565b5b6000610a18848285016109df565b91505092915050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000610a57601f83610962565b9150610a6282610a21565b602082019050919050565b60006020820190508181036000830152610a8681610a4a565b905091905056fea26469706673582212209d4259332865a4705a14637bd9479c8c8dcf5caf32699190876664bcad3dce5d64736f6c63430008110033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 24 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.