set-in-stone – 坚如磐石区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,set-in-stone – 坚如磐石区块链毕设代写 是一篇很好的国外资料

set-in-stone

This repository has been created in order to publish a demo of my interview with Thomas, CEO of Set In Stone.

To Thomas,

Dear Thomas, in order to show how one could proceed, I published some files of a personal project that is similar to the Rugby game exercice. What is called card can be tought of as Pool. As a card, a Pool is defined as structure that defines Pool’s variables. These variables – which represent properties of the Pool – can be static (in that case, they are defined during the Pool creation) or dynamique (in that case one needs a function that can modify them).

Minting NFTs (ERC721 tokens)

ERC721 is a standard interface for non-fungible tokens (NFT). It defines an Interface that must be imported and defined in a contract which allows minting NFTs. The interface can be found here [ERC721 interface]. In the NFT.sol contract that I proposed, the openzeppelin library has been used, which provides a ready to use ERC721 interface, this openzeppelin interface can be found here [ERC721 interface, openzeppelin]. One then needs to define our function that allows to trigger all operations needed when minting the NFT, this is the mintImage function defined in line 43 of NFT.sol contract. The image can be replaced by a card.

// mintImage function mintImage(string memory _imageCID) public {         // cannot mint the same image twice.         // IPFS will be used to store images returning a unique CID (image URI).         // Since CIDs are based on the image content, same image will always         // return same CID.         require(!imageAlreadyMinted[_imageCID], "image already minted");         uint256 newImageId = counter;          // store the image URI on the Blockchain         images.push(_imageCID);          // mint the image         _safeMint(msg.sender, newImageId);          // store the information that the image has been minted         imageAlreadyMinted[_imageCID] = true;          // store the image ID of the image in a mapping         imageIDs[_imageCID] = newImageId;          // transfer the ownership of the image         owner = payable(ownerOf(newImageId));          counter++;     }

Rugby Game

The rugby game that we discussed today is similar to one of my personal project that I called Pool game (see the contract PoolGame.sol). As you can see, I created a structure called VPool (line 12) that defines all properties of the Pool (which can be tought of as the card in our case). The Card structure could be defined as the VPool structure.

// VPool structure struct VPool {         bool registered;         string ID;         uint256 price;         uint256 prize;         uint256 numberOfUsers;         uint256 numberOfVoters;         uint256 startRegistrationTime;         uint256 endRegistrationTime;         uint256 endTime;         mapping(address => bool) userVoted;         mapping(address => uint256) userVote;         mapping(uint256 => address) voterAddresses;         mapping(address => bool) userWithdrawed;     }       //====================================  //           CARD STRUCTURE  //====================================  struct Card {         address creator    // l'adresse de l'utilisateur qui a créé la carte         string cardID;         bool created;         string position;   // or uint256         string firstname;         string lastname;         string club;         string scarcity;   // rareté         uint256 season;    // saison         uint256 strength;  // Force         uint256 endurance;         uint256 speed;     // vitesse         uint256 level;     // level         uint256 amount;    // le montant à payer pour ouvrir un booster         uint256 openMode;  // 0 quand la carte est créée via un échange, et 1 quand elle créée en ouvrant un booster     }

Other properties can be added to the Card structure in case they are necessary. To create a new Card, one needs to create a function, similar to the RegisterOrJoinPool in PoolGame.sol smart contract (line 88). It takes two parameters, the VPool ID (string) and an amount of tokens that is necessary to join the VPool. In the case of the Rugby game, the CreateCard function can take same parameteres (Card ID, amount to pay to open a booster), plus all properties that need to be defined at Card creation.

// CreateCard.sol function CreateCard(         string  _CardID,         uint256 _amount,         string _position,         string firstname,         string _lastname,         string _club,         string _scarcity,         uint256 _season,         uint256 _strength,         uint256 _endurance,         uint256 _speed,         uint256 level,         uint256 _openMode ) public {         // here I supposed there exists a mapping between an address (user address) and the Card structure         // mapping(address => Card) internal cards;                  // Define all the requires here (for example the Card must not be registered, etc...)                   cards[msg.sender].creator = msg.sender;         cards[msg.sender].cardID = _CardID;         cards[msg.sender].created = true;         cards[msg.sender].position = _position;         cards[msg.sender].firstname = _firstname;         cards[msg.sender].lastname = _lastname;         cards[msg.sender].club = _club;         cards[msg.sender].scarcity = _scarcity;         cards[msg.sender].season = _season;         cards[msg.sender].strength = _strength;         cards[msg.sender].endurance = _endurance;         cards[msg.sender].speed = _speed;         cards[msg.sender].level = _level;         cards[msg.sender].amount = _amount;         cards[msg.sender].OpenMode = _openMode;     }

Random number generator

The generation of random number in solidity is active field of research. Two solutions are proposed in this demo, the first one consists of using the ChainLink Verifiable Random Function to generate a random number ([ERC721 interface], this requires filling the contract with Link tokens and requiring the user that call the contract to have somre Link tokens in their wallets. The second method that I proposed and that is implemented in my Pool game is to define a function randDistribution in the smart contract that generates a random number. To avoid paying gas fees when calling this function, no state variable must be modified inside the function, therefore, this must be a view function that return a random number. Let’s suppose one needs to generate N distinct random numbers, the following function allows to accomplish that task.

// generates an array of random numbers between 1 and the length of the array     function randomNumbersGerator(         string memory _cardID,         uint256[] memory _initialTab     ) public view returns (uint256[] memory) {         // all requires must be set here          uint256 p = _initialTab.length;         uint256 k = _initialTab.length;          // generate random numbers         // be aware that block.timestamp can be alter by miners.         for (uint256 i = 0; i < k; i++) {             uint256 randNum = (uint256(                 keccak256(abi.encodePacked(block.timestamp, _cardID, _initialTab[i]))             ) % p) + 1;              uint256 tmp = _initialTab[randNum - 1];             _initialTab[randNum - 1] = _initialTab[p - 1];             _initialTab[p - 1] = tmp;             p = p - 1;         }          uint256[] memory res;         res = _initialTab;          return res;     }

The above function generates an array of distinct random numbers, the length of this array is equal to the length of the initial array given as parameter. The _initialTab array must be constructed such that to have 1 at index 0, 2 at index 1, 3 at index 2, …., N at index N – 1. Where N is the number of random number one would like to generate. The random numbers generated are in the range 1 – N.

// the _initialTab for generating 5 random numbers _initialTab[0] = 1; _initialTab[1] = 2; _initialTab[2] = 3; _initialTab[3] = 4; _initialTab[4] = 5;

Video (random numbers generator)

This video shows the generation of random numbers by using the function randomNumbersGerator defined above.

set-in-stone - 坚如磐石

some updates for RugbyBlochain.sol


石头镶嵌

创建此存储库是为了发布我与SetInStone首席执行官Thomas的访谈演示

致托马斯,

亲爱的托马斯,为了展示如何进行,我发布了一些类似橄榄球比赛练习的个人项目文件。所谓的卡可以被称为池。作为卡片,池被定义为定义池变量的结构。这些变量(表示池的属性)可以是静态的(在这种情况下,它们是在池创建期间定义的)或动态的(在这种情况下,需要一个可以修改它们的函数)

铸造NFT(ERC721代币)

我们今天讨论的橄榄球比赛类似于我个人的一个项目,我称之为台球比赛(参见contract PoolGame.sol)。如您所见,我创建了一个名为VPool(第12行)的结构,该结构定义了池的所有属性(在我们的例子中,它可以被称为卡)。卡结构可以定义为VPool结构

// mintImage function mintImage(string memory _imageCID) public {         // cannot mint the same image twice.         // IPFS will be used to store images returning a unique CID (image URI).         // Since CIDs are based on the image content, same image will always         // return same CID.         require(!imageAlreadyMinted[_imageCID], "image already minted");         uint256 newImageId = counter;          // store the image URI on the Blockchain         images.push(_imageCID);          // mint the image         _safeMint(msg.sender, newImageId);          // store the information that the image has been minted         imageAlreadyMinted[_imageCID] = true;          // store the image ID of the image in a mapping         imageIDs[_imageCID] = newImageId;          // transfer the ownership of the image         owner = payable(ownerOf(newImageId));          counter++;     }

橄榄球游戏

如果需要,可以将其他属性添加到卡结构中。要创建新卡,需要创建一个函数,类似于PoolGame.sol智能合约(第88行)中的RegisterOrJoinPool。它需要两个参数,VPool ID(字符串)和加入VPool所需的令牌数量。在橄榄球游戏中,CreateCard函数可以采用相同的参数(卡ID、打开增压器所需支付的金额),以及创建卡时需要定义的所有属性

// VPool structure struct VPool {         bool registered;         string ID;         uint256 price;         uint256 prize;         uint256 numberOfUsers;         uint256 numberOfVoters;         uint256 startRegistrationTime;         uint256 endRegistrationTime;         uint256 endTime;         mapping(address => bool) userVoted;         mapping(address => uint256) userVote;         mapping(uint256 => address) voterAddresses;         mapping(address => bool) userWithdrawed;     }       //====================================  //           CARD STRUCTURE  //====================================  struct Card {         address creator    // l'adresse de l'utilisateur qui a créé la carte         string cardID;         bool created;         string position;   // or uint256         string firstname;         string lastname;         string club;         string scarcity;   // rareté         uint256 season;    // saison         uint256 strength;  // Force         uint256 endurance;         uint256 speed;     // vitesse         uint256 level;     // level         uint256 amount;    // le montant à payer pour ouvrir un booster         uint256 openMode;  // 0 quand la carte est créée via un échange, et 1 quand elle créée en ouvrant un booster     }

固体中随机数的产生是一个活跃的研究领域。本演示中提出了两种解决方案,第一种解决方案包括使用ChainLink可验证随机函数生成随机数([ERC721接口”),这要求使用链接令牌填充合同,并要求调用合同的用户在钱包中放置somre链接令牌。我提出的第二种方法是在我的池游戏中实现的,它是在智能合约中定义一个函数randDistribution,它生成一个随机数。为了避免在调用此函数时支付煤气费,不必在函数内部修改任何状态变量,因此,此函数必须是返回随机数的视图函数。假设需要生成N个不同的随机数,下面的函数允许完成该任务

// CreateCard.sol function CreateCard(         string  _CardID,         uint256 _amount,         string _position,         string firstname,         string _lastname,         string _club,         string _scarcity,         uint256 _season,         uint256 _strength,         uint256 _endurance,         uint256 _speed,         uint256 level,         uint256 _openMode ) public {         // here I supposed there exists a mapping between an address (user address) and the Card structure         // mapping(address => Card) internal cards;                  // Define all the requires here (for example the Card must not be registered, etc...)                   cards[msg.sender].creator = msg.sender;         cards[msg.sender].cardID = _CardID;         cards[msg.sender].created = true;         cards[msg.sender].position = _position;         cards[msg.sender].firstname = _firstname;         cards[msg.sender].lastname = _lastname;         cards[msg.sender].club = _club;         cards[msg.sender].scarcity = _scarcity;         cards[msg.sender].season = _season;         cards[msg.sender].strength = _strength;         cards[msg.sender].endurance = _endurance;         cards[msg.sender].speed = _speed;         cards[msg.sender].level = _level;         cards[msg.sender].amount = _amount;         cards[msg.sender].OpenMode = _openMode;     }

随机数生成器

上述函数生成一个不同随机数的数组,该数组的长度等于作为参数给定的初始数组的长度。必须构造_initialTab数组,以便在索引0处有1,在索引1处有2,在索引2处有3,…,在索引N-1处有N。其中N是一个要生成的随机数。生成的随机数在1-N范围内

// generates an array of random numbers between 1 and the length of the array     function randomNumbersGerator(         string memory _cardID,         uint256[] memory _initialTab     ) public view returns (uint256[] memory) {         // all requires must be set here          uint256 p = _initialTab.length;         uint256 k = _initialTab.length;          // generate random numbers         // be aware that block.timestamp can be alter by miners.         for (uint256 i = 0; i < k; i++) {             uint256 randNum = (uint256(                 keccak256(abi.encodePacked(block.timestamp, _cardID, _initialTab[i]))             ) % p) + 1;              uint256 tmp = _initialTab[randNum - 1];             _initialTab[randNum - 1] = _initialTab[p - 1];             _initialTab[p - 1] = tmp;             p = p - 1;         }          uint256[] memory res;         res = _initialTab;          return res;     }

本视频展示了使用上面定义的函数RandomNumberGerator生成随机数的过程

// the _initialTab for generating 5 random numbers _initialTab[0] = 1; _initialTab[1] = 2; _initialTab[2] = 3; _initialTab[3] = 4; _initialTab[4] = 5;

视频(随机数生成器)

set-in-stone - 坚如磐石

set-in-stone - 坚如磐石

some updates for RugbyBlochain.sol

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/24244.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » set-in-stone – 坚如磐石区块链毕设代写

提供最优质的资源集合

立即查看 了解详情