3M/MMM互助智能合約開發(fā)穩(wěn)定版,MMM/3M互助智能合約系統(tǒng)開發(fā)詳細(xì)說明及案例源碼
web3.js是一個(gè)JavaScript API庫。要讓DApp在以太坊上運(yùn)行,我們可以使用web3.js庫提供的web3對(duì)象。web3.js通過RPC調(diào)用與本地節(jié)點(diǎn)通信,它可以與任何公開RPC層的以太坊節(jié)點(diǎn)一起使用。web3包含eth對(duì)象-web3.eth(用于與以太坊區(qū)塊鏈交互)和shh對(duì)象-web3.shh(用于與Whisper交互)
dapp定制開發(fā)技術(shù)主要包括以太坊智能合約定制開發(fā),詳細(xì)流程:I35功能7O98開發(fā)O7I8 包括智能合約語言Solidity開發(fā),以太坊智能合約框架Truffle開發(fā),Web3.js開發(fā),以太坊區(qū)塊鏈瀏覽器Mist開發(fā)等。這些技術(shù)可以幫助開發(fā)者快速構(gòu)建出功能強(qiáng)大、可靠性高的dapp。
此外,dapp定制開發(fā)還涉及到以太坊智能合約測試、以太坊智能合約安全性測試、以太坊智能合約部署測試等。這些技術(shù)可以幫助開發(fā)者快速測試和部署dapp,從而確保dapp的可靠性和安全性。
數(shù)據(jù)作為新型生產(chǎn)要素,能為實(shí)體經(jīng)濟(jì)帶來放大、疊加和倍增作用,是做強(qiáng)做優(yōu)做大數(shù)字經(jīng)濟(jì)的關(guān)鍵。
建立數(shù)據(jù)可信流通體系,增強(qiáng)數(shù)據(jù)的可用、可信、可流通、可追溯水平,是激活數(shù)據(jù)要素潛能、賦能實(shí)體經(jīng)濟(jì)的重要途徑。區(qū)塊鏈技術(shù)具有去中心化、共識(shí)機(jī)制、不可篡改、可以追溯、規(guī)則透明等特點(diǎn)。
ERC-721的基礎(chǔ)知識(shí)在這個(gè)Infura博客中有所介紹。我們選擇使用ERC721URIStorage,這樣就不必使用靜態(tài)元數(shù)據(jù)文件來填充tokenURI。目前為止,我們導(dǎo)入了剛才自己創(chuàng)建的接口和OpenZeppelin的ERC721URIStorage實(shí)現(xiàn),并讓我們的ERC4907智能合約繼承它們的屬性,如下:
//SPDX-License-Identifier:MIT
pragma solidity>=0.4.22<0.9.0;
import"openzeppelin/contracts/token/ERC721/ERC721URIStorage.sol";
import"./IERC4907.sol";
contract ERC4907 is ERC721URIStorage,IERC4907{
constructor()public{
}
}
contract ERC4907 is ERC721,IERC4907{
constructor(string memory _name,string memory _symbol)ERC721(_name,_symbol){
}
}
contract ERC4907 is ERC721URIStorage,IERC4907{
struct UserInfo{
address user;//address of user role
uint64 expires;//unix timestamp,user expires
}
mapping(uint256=>UserInfo)internal _users;
///notice set the user and expires of a NFT
///dev The zero address indicates there is no user
///Throws if`tokenId`is not valid NFT
///param user The new user of the NFT
///param expires UNIX timestamp,The new user could use the NFT before expires
function setUser(uint256 tokenId,address user,uint64 expires)public virtual override{
require(_isApprovedOrOwner(msg.sender,tokenId),"ERC721:transfer caller is not owner nor approved");
UserInfo storage info=_users[tokenId];
info.user=user;
info.expires=expires;
emit UpdateUser(tokenId,user,expires);
}
///notice Get the user address of an NFT
///dev The zero address indicates that there is no user or the user is expired
///param tokenId The NFT to get the user address for
///return The user address for this NFT
function userOf(uint256 tokenId)
public
view
virtual
override
returns(address)
{
if(uint256(_users[tokenId].expires)>=block.timestamp){
return _users[tokenId].user;
}else{
return address(0);
}
}