Created
September 5, 2022 21:37
-
-
Save libert-xyz/ad78e8770df5857bb7b78261ec015116 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.16+commit.07a7930e.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
contract Structs { | |
struct Car { | |
string model; | |
uint year; | |
address owner; | |
} | |
Car public car; | |
Car[] public cars; | |
mapping(address => Car[]) public carsByOwner; | |
function examples() external { | |
Car memory toyota = Car("Toyota", 1988, msg.sender); | |
Car memory lambo = Car({model: "Batman", year: 2019, owner: msg.sender}); | |
Car memory tesla; | |
tesla.model = "Tesla"; | |
tesla.year = 2020; | |
tesla.owner = msg.sender; | |
cars.push(toyota); | |
cars.push(lambo); | |
cars.push(tesla); | |
cars.push(Car("Ferrari", 2022, msg.sender)); | |
Car storage _car = cars[0]; | |
//update toyota | |
_car.year = 1999; | |
delete _car.owner; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment