-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathMyStructs.sol
40 lines (31 loc) · 1.01 KB
/
MyStructs.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyStructs {
struct NFT {
string name;
uint256 dna;
}
NFT[] public nftList;
function addNFT(string memory _name, uint256 _dna) public {
// NFT memory newNFT;
// newNFT.name = _name;
// newNFT.dna = _dna;
NFT memory newNFT = NFT(_name, _dna);
nftList.push(newNFT);
}
function addNFTS(NFT[] calldata _nfts) public {
nftList = _nfts;
}
function updateNFTStorage(uint256 _index, string memory _name) public {
NFT storage nftToBeUpdated = nftList[_index];
nftToBeUpdated.name = _name;
}
function updateNFTMemory(uint256 _index, string memory _name) public {
NFT memory nftToBeUpdated = nftList[_index];
nftToBeUpdated.name = _name;
nftList[_index] = nftToBeUpdated;
}
function getNftName(uint256 _index) public view returns(string memory){
return nftList[_index].name;
}
}