Loading Learn Solidity basics/Notes.md +13 −1 Original line number Diff line number Diff line Loading @@ -315,8 +315,20 @@ covers interfaces ### Part 11 video link <https://www.youtube.com/watch?v=SPeKei4K-18> ### Part 11 related .sol files ### Part 11 notes - [MyContractCalls.sol](./contracts/MyContractCalls.sol) - [MyInport.sol](./contracts/MyImport.sol) ### Part 11 notes - course covers imports from web or other local .sol files - instead of declaring a variable with `string` you could declare it with `bytes32` instead - this uses less gas than strings - strings are essentially just bytes - there is a way to convert any data into a hash - in Solidity, the hashing algorithm used is Keccak256 - why is this important? it helps with validation - this is like what they do with passwords on normal databases Learn Solidity basics/contracts/MyContractCalls.sol 0 → 100644 +23 −0 Original line number Diff line number Diff line // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // contract deployed @ 0x599DB3Ffbba36FfaAB3f86e92e1fCA0465b2CDeA contract MyOtherContract { uint256 public age = 29; function getAge() public view returns (uint256) { return age; } } contract MyContractCalls { function getAgeFromOtherContract(address _otherContractAddress) public view returns (uint256) { MyOtherContract other = MyOtherContract(_otherContractAddress); uint256 age = other.getAge(); return age; } } Learn Solidity basics/contracts/MyImport.sol 0 → 100644 +36 −0 Original line number Diff line number Diff line // SPDX-License-Identifier: MIT pragma solidity 0.8.20; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; import "./MyLoop.sol"; contract NFT { string name; uint256 dna; constructor(string memory _name, uint256 _dna) { name = _name; dna = _dna; } } contract MyImport is ERC721, MyLoop { NFT[] public nfts; // NFT type must be either imported or declared in same file string myName = "Chris"; bytes32 myBytesName = "Chris"; // this is supported, and sometimes it's better to use bytes32 to declare strings than strings themselves // bytes take less gas than strings do constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {} function addNFT(string memory _name, uint256 _dna) public { NFT nft = new NFT(_name, _dna); nfts.push(nft); } function myHashedName(string memory _name) public pure returns (bytes32) { return keccak256(abi.encodePacked(_name)); } } Loading
Learn Solidity basics/Notes.md +13 −1 Original line number Diff line number Diff line Loading @@ -315,8 +315,20 @@ covers interfaces ### Part 11 video link <https://www.youtube.com/watch?v=SPeKei4K-18> ### Part 11 related .sol files ### Part 11 notes - [MyContractCalls.sol](./contracts/MyContractCalls.sol) - [MyInport.sol](./contracts/MyImport.sol) ### Part 11 notes - course covers imports from web or other local .sol files - instead of declaring a variable with `string` you could declare it with `bytes32` instead - this uses less gas than strings - strings are essentially just bytes - there is a way to convert any data into a hash - in Solidity, the hashing algorithm used is Keccak256 - why is this important? it helps with validation - this is like what they do with passwords on normal databases
Learn Solidity basics/contracts/MyContractCalls.sol 0 → 100644 +23 −0 Original line number Diff line number Diff line // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // contract deployed @ 0x599DB3Ffbba36FfaAB3f86e92e1fCA0465b2CDeA contract MyOtherContract { uint256 public age = 29; function getAge() public view returns (uint256) { return age; } } contract MyContractCalls { function getAgeFromOtherContract(address _otherContractAddress) public view returns (uint256) { MyOtherContract other = MyOtherContract(_otherContractAddress); uint256 age = other.getAge(); return age; } }
Learn Solidity basics/contracts/MyImport.sol 0 → 100644 +36 −0 Original line number Diff line number Diff line // SPDX-License-Identifier: MIT pragma solidity 0.8.20; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; import "./MyLoop.sol"; contract NFT { string name; uint256 dna; constructor(string memory _name, uint256 _dna) { name = _name; dna = _dna; } } contract MyImport is ERC721, MyLoop { NFT[] public nfts; // NFT type must be either imported or declared in same file string myName = "Chris"; bytes32 myBytesName = "Chris"; // this is supported, and sometimes it's better to use bytes32 to declare strings than strings themselves // bytes take less gas than strings do constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {} function addNFT(string memory _name, uint256 _dna) public { NFT nft = new NFT(_name, _dna); nfts.push(nft); } function myHashedName(string memory _name) public pure returns (bytes32) { return keccak256(abi.encodePacked(_name)); } }