链上NFT铸造发行交易平台开发功能分析源码部署

308 阅读3分钟

  NFT根据以太坊ERC721或其他标准,【18I链上合约-259l开发系统3365】,将作品加密后变成了一种非同质化的代币,而这叫做铸币(mint)。

  2、铸币是需要和区块链签约,要支付手续费(Gas费),而这笔手续费是支付给各节点的矿工,需要矿工将签约记录到区块链内。记录的过程需要计算哈希函数,随机值,哈希值,并生成新的区块;

  3、NFT铸币完成后,产品就上架到交易平台OpenSea上可供交易。当交易NFT作品时,系统会向区块链发送交易合约,然后各节点开始计算哈希函数,随机值,哈希值,然后生成确权代码,以及校验生成的区块是否有效;

  4、以太坊区块链是基于比特币区块链上发展和进步的,其在比特币区块链的基础上增加了智能合约的设定,而NFT基于以太坊。所以NFT有了区块链去中心化和智能合约的特点,使NFT具有不可替代、不可分割、不可篡改等区块链的特点;

  跨链互操作性有利于Web3不同生态的集成,同时对于连接现有Web2基础设施和Web3服务有至关重要的作用。通过启用跨链智能合约,跨链互操作性解决方案减少了生态系统的碎片化,并释放了更高的资本效率和更好的流动性条件

pragma solidity ^0.6.0; import "./IERC165.sol";

/// /// @dev Interface for the NFT Royalty Standard /// interface IERC2981 is IERC165 { /// ERC165 bytes to add to interface array - set in parent contract /// implementing this standard /// /// bytes4(keccak256("royaltyInfo(uint256,uint256)")) == 0x2a55205a /// bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a; /// _registerInterface(_INTERFACE_ID_ERC2981);

/// @notice Called with the sale price to determine how much royalty
//          is owed and to whom.
/// @param _tokenId - the NFT asset queried for royalty information
/// @param _salePrice - the sale price of the NFT asset specified by _tokenId
/// @return receiver - address of who should be sent the royalty payment
/// @return royaltyAmount - the royalty payment amount for _salePrice
function royaltyInfo(
    uint256 _tokenId,
    uint256 _salePrice
) external view returns (
    address receiver,
    uint256 royaltyAmount
);

}

interface IERC165 { /// @notice Query if a contract implements an interface /// @param interfaceID The interface identifier, as specified in ERC-165 /// @dev Interface identification is specified in ERC-165. This function /// uses less than 30,000 gas. /// @return true if the contract implements interfaceID and /// interfaceID is not 0xffffffff, false otherwise function supportsInterface(bytes4 interfaceID) external view returns (bool); } NFT 跨链桥是如何做到的?

NFT 桥适用在所有的鼓励的链之间来回传送 NFT,与此同时保存其数据库。当一个 NFT 被迁移出它发源链时,会出现这样的情况:

1)NFT 被锁定在 NFT 桥区块链智能合约中;

2)一个等效电路产品的包装 NFT 被锻造到总体目标链里的相对应 collection 中;

3)那个被包装 NFT 同名的,看上去和原先的一样,个人行为也与链里的别的 NFT 完全一样,在 EVM 链上,包装 NFT 是 ERC721 货币,在 Solana 上,他们带有 Metaplex 数据库的 SPL 货币,在 Aptos 上,它们都是 Aptos 货币标准化的案例。

除开名称及外型以外,被包装 NFT 的独特之处取决于可以把它们推送回初始链并开启初始 NFT。这就意味着,比如,源于 Aptos 的 NFT 能够桥收到以太币,之后在 Opensea 上售卖,然后再由新使用者转到 Aptos。

在 NFT 数据存储中,我们可以看到 solmate 等常规实现都使用了 mapping(uint256=>address)internal _ownerOf 将单个 tokenId 与持有者对应。但 ERC721A 是对批量铸造进行特殊优化的,开发者认为在批量铸造过程中,用户持有的 NFT 的 tokenId 往往是连续的。

_ownerOf 记录 tokenId 与持有者的关系

_balanceOf 记录持有人所持有的 NFT 数量

其铸造方法定义如下:

function _mint(address to,uint256 id)internal virtual{

require(to!=address(0),"INVALID_RECIPIENT");

require(_ownerOf[id]==address(0),"ALREADY_MINTED");

//Counter overflow is incredibly unrealistic.

unchecked{

_balanceOf[to]++;

}

_ownerOf[id]=to;

emit Transfer(address(0),to,id);

}