156 | );
157 | }
158 | }
159 |
160 | export default App;
161 |
--------------------------------------------------------------------------------
/Day6/React Lottery App/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/Day1/README.md:
--------------------------------------------------------------------------------
1 | # Workshop DAY 1 - Blockchain Basics
2 |
3 | ## Content
4 | - What is Blockchain ?
5 | - Understanding SHA256
6 | - Immutable ledger
7 | - Distributed P2P network
8 | - Mining
9 | - Consensus
10 |
11 | ## History:
12 | - [“How to time stamp a digital document” 1991 by Stuart Haber.](http://www.staroceans.org/e-book/Haber_Stornetta.pdf)
13 |
14 | ## What do you understand by BLOCKCHAIN?
15 | - BLOCK + CHAIN
16 |
17 |
18 | ## Looking inside a block from bird's view.
19 |
20 |
21 | ## Basic overview of a chain
22 |
23 | - First block is called Genesis Block
24 |
25 | ## Backbone of Blockchain
26 | - Mining
27 | - Consensus
28 | - Hash
29 | - Immutable Ledger
30 | - P2P Network
31 |
32 | ## Hashing
33 | - Hashing is like a unique identity for every unique individual. Likefingerprint of humans
34 |
35 |
36 | - Similarity with real world
37 |
38 |
39 | ### Example: SHA256
40 | - NSA
41 | - 64 CHARACTER
42 | - 256 BITS
43 | - HEXA DECIMAL
44 | - Eg. ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
45 | - Demo : https://andersbrownworth.com/blockchain/hash
46 |
47 | ### Properties of good hashing algorithm
48 | - One way
49 | - Deterministic
50 | - Fast computation
51 | - The Avalanche effect
52 | - Withstand collision
53 |
54 | ## Immutable ledger
55 |
56 |
57 |
58 | ### Distributed Peer to Peer Network
59 |
60 |
61 | ### DATA ON CHAIN
62 |
63 |
64 | ### TAMPERING DATA
65 |
66 |
67 | ### Recovering
68 |
69 |
70 |
71 |
72 |
73 |
74 | ## Mining
75 |
76 |
77 | ## CONSENSUS PROTOCOL
78 | Through consensus algorithms reliability is achieved in the Blockchain network and establish trust between unknown peers in a distributed computing environment.
79 |
80 | - PROOF OF WORK
81 | - PROOF OF STAKE
82 |
83 | ## Let's play around with BLOCKCHAIN
84 | [BLOCKCHAIN DEMO](https://andersbrownworth.com/blockchain/blockchain)
85 |
86 | ## Why Blockchain?
87 | - Decentralized System: Decentralized nature of blockchain make the resources shared to everyone, as it does not store its information at any central location but the blockchain is copied and spread across a network of computers.
88 | - Security: Even in today’s era digitalization we are facing a lot of password related threats, data tampering, unauthorized access. The numerous cases of data leaks that has shaken the trust of the people at a large extent. But the blockchain technology is creating trust in an untrusting ecosystem, making it a potentially strong cybersecurity technology.
89 | - Transparency: There is a lack of trust between companies and consumers in sharing their personal data. There is no involvement of participants so that they know no tampering has been done with the data. But in the case of blockchain everything is visible to all the participants from the beginning till date.
90 | - No intermediaries: Blockchain has efficiently eliminate the role of intermediaries by removing the need of central authority.
91 |
92 | ## Let me ask you guys a few question.
93 |
94 | - How much sure you are about the wine you drink is labeled as a fair trade product?
95 | - Are you sure about the identity of a person you meet online is legit?
96 | - Is the healthcare insurance company sure about that the person is not suffering from any diseases by just looking at the medical reports? What if it’s tampered?
97 | - Are you sure that even after providing multi factor authorization your data is secured?
98 | - Are you sure that the donations you are giving for a charity purpose are really reaching to the right person?
99 | - Are you sure if no one is reading your chats, accessing you data , listening to your calls except you and the other person?
100 |
101 |
102 | If you are sure about the every question I asked then definitely you are lying. Isn’t? And what if I tell you blockchain resolves all these problems even more that that? Let me assure you that it does. In order to be 100% sure you need to take a ride of this blockchain journey with me .
103 |
--------------------------------------------------------------------------------
/Day4/README.md:
--------------------------------------------------------------------------------
1 | # ERC721
2 | - Ethereum Request for Comment 721
3 | - Non Fungible
4 |
5 | ## Interface
6 | `
7 | interface IERC721 {
8 | function balanceOf(address owner) external view returns (uint balance);
9 |
10 | function ownerOf(uint tokenId) external view returns (address owner);
11 |
12 | function safeTransferFrom(address from, address to, uint tokenId) external;
13 |
14 | function safeTransferFrom(
15 | address from,
16 | address to,
17 | uint tokenId,
18 | bytes calldata data
19 | ) external;
20 |
21 | function transferFrom(address from, address to, uint tokenId) external;
22 |
23 | function approve(address to, uint tokenId) external;
24 |
25 | function getApproved(uint tokenId) external view returns (address operator);
26 |
27 | function setApprovalForAll(address operator, bool _approved) external;
28 |
29 | function isApprovedForAll(
30 | address owner,
31 | address operator
32 | ) external view returns (bool);
33 | }
34 | `
35 |
36 | ## Implementing
37 |
38 | `
39 | contract ERC721 is IERC721 {
40 | event Transfer(address indexed from, address indexed to, uint indexed id);
41 | event Approval(address indexed owner, address indexed spender, uint indexed id);
42 | event ApprovalForAll(
43 | address indexed owner,
44 | address indexed operator,
45 | bool approved
46 | );
47 |
48 | // Mapping from token ID to owner address
49 | mapping(uint => address) internal _ownerOf;
50 |
51 | // Mapping owner address to token count
52 | mapping(address => uint) internal _balanceOf;
53 |
54 | // Mapping from token ID to approved address
55 | mapping(uint => address) internal _approvals;
56 |
57 | // Mapping from owner to operator approvals
58 | mapping(address => mapping(address => bool)) public isApprovedForAll;
59 |
60 | function ownerOf(uint id) external view returns (address owner) {
61 | owner = _ownerOf[id];
62 | require(owner != address(0), "token doesn't exist");
63 | }
64 |
65 | function balanceOf(address owner) external view returns (uint) {
66 | require(owner != address(0), "owner = zero address");
67 | return _balanceOf[owner];
68 | }
69 |
70 | function setApprovalForAll(address operator, bool approved) external {
71 | isApprovedForAll[msg.sender][operator] = approved;
72 | emit ApprovalForAll(msg.sender, operator, approved);
73 | }
74 |
75 | function approve(address spender, uint id) external {
76 | address owner = _ownerOf[id];
77 | require(
78 | msg.sender == owner || isApprovedForAll[owner][msg.sender],
79 | "not authorized"
80 | );
81 |
82 | _approvals[id] = spender;
83 |
84 | emit Approval(owner, spender, id);
85 | }
86 |
87 | function getApproved(uint id) external view returns (address) {
88 | require(_ownerOf[id] != address(0), "token doesn't exist");
89 | return _approvals[id];
90 | }
91 |
92 | function _isApprovedOrOwner(
93 | address owner,
94 | address spender,
95 | uint id
96 | ) internal view returns (bool) {
97 | return (spender == owner ||
98 | isApprovedForAll[owner][spender] ||
99 | spender == _approvals[id]);
100 | }
101 |
102 | function transferFrom(address from, address to, uint id) public {
103 | require(from == _ownerOf[id], "from != owner");
104 | require(to != address(0), "transfer to zero address");
105 |
106 | require(_isApprovedOrOwner(from, msg.sender, id), "not authorized");
107 |
108 | _balanceOf[from]--;
109 | _balanceOf[to]++;
110 | _ownerOf[id] = to;
111 |
112 | delete _approvals[id];
113 |
114 | emit Transfer(from, to, id);
115 | }
116 |
117 | function safeTransferFrom(address from, address to, uint id) external {
118 | transferFrom(from, to, id);
119 |
120 | require(
121 | to.code.length == 0 ||
122 | IERC721Receiver(to).onERC721Received(msg.sender, from, id, "") ==
123 | IERC721Receiver.onERC721Received.selector,
124 | "unsafe recipient"
125 | );
126 | }
127 |
128 | function safeTransferFrom(
129 | address from,
130 | address to,
131 | uint id,
132 | bytes calldata data
133 | ) external {
134 | transferFrom(from, to, id);
135 |
136 | require(
137 | to.code.length == 0 ||
138 | IERC721Receiver(to).onERC721Received(msg.sender, from, id, data) ==
139 | IERC721Receiver.onERC721Received.selector,
140 | "unsafe recipient"
141 | );
142 | }
143 |
144 | function _mint(address to, uint id) internal {
145 | require(to != address(0), "mint to zero address");
146 | require(_ownerOf[id] == address(0), "already minted");
147 |
148 | _balanceOf[to]++;
149 | _ownerOf[id] = to;
150 |
151 | emit Transfer(address(0), to, id);
152 | }
153 |
154 | function _burn(uint id) internal {
155 | address owner = _ownerOf[id];
156 | require(owner != address(0), "not minted");
157 |
158 | _balanceOf[owner] -= 1;
159 |
160 | delete _ownerOf[id];
161 | delete _approvals[id];
162 |
163 | emit Transfer(owner, address(0), id);
164 | }
165 | }
166 | `
167 |
168 | ## Implementation using openzepellin
169 |
170 | `
171 | // SPDX-License-Identifier: MIT
172 | pragma solidity ^0.8.9;
173 |
174 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
175 | import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
176 | import "@openzeppelin/contracts/access/Ownable.sol";
177 |
178 | contract MyToken is ERC721, ERC721Burnable, Ownable {
179 | constructor() ERC721("MyToken", "MTK") {}
180 |
181 | function _baseURI() internal pure override returns (string memory) {
182 | return "https://dummyurl/";
183 | }
184 |
185 | function safeMint(address to, uint256 tokenId) public onlyOwner {
186 | _safeMint(to, tokenId);
187 | }
188 | }
189 | `
190 |
191 | ## URI
192 | URI stands for Universal Resource Identifier. Think of it as an URL, through which you can get all metadata associated with the NFT. The metadata can be image URL, description, attributes, etc.
193 |
194 | ## URI Standard
195 | - URI standard of OPEN SEA
196 |
197 | `
198 | {
199 | "description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
200 | "external_url": "https://openseacreatures.io/3",
201 | "image": "https://storage.googleapis.com/opensea-prod.appspot.com/puffs/3.png",
202 | "name": "Dave Starbelly",
203 | "attributes": [ ... ]
204 | }
205 | `
206 | [OPENSEA STANDARD](https://docs.opensea.io/docs/metadata-standards)
207 |
208 |
209 |
--------------------------------------------------------------------------------
/Day2/README.md:
--------------------------------------------------------------------------------
1 | # Workshop DAY 2 - Blockchain Basics
2 |
3 | ## Content
4 | - Introduction to Ethereum
5 | - Introduction to Remix
6 | - Introduction to Solidity
7 |
8 | ## Introtuction to Remix: [Remix IDE](https://remix.ethereum.org/)
9 |
10 | ## Introductin to Solidity
11 |
12 | ### Doc
13 | [Official Doc](https://docs.soliditylang.org/en/v0.8.19/)
14 |
15 |
16 | ### Sample Contract
17 |
18 | ```
19 | // SPDX-License-Identifier: GPL-3.0
20 |
21 | pragma solidity >=0.8.2 <0.9.0;
22 |
23 | /**
24 | * @title Storage
25 | * @dev Store & retrieve value in a variable
26 | * @custom:dev-run-script ./scripts/deploy_with_ethers.ts
27 | */
28 | contract Storage {
29 |
30 | uint256 number;
31 |
32 | /**
33 | * @dev Store value in variable
34 | * @param num value to store
35 | */
36 | function store(uint256 num) public {
37 | number = num;
38 | }
39 |
40 | /**
41 | * @dev Return value
42 | * @return value of 'number'
43 | */
44 | function retrieve() public view returns (uint256){
45 | return number;
46 | }
47 | }
48 | ```
49 |
50 | ### define the Solidity version compiler
51 |
52 | ```
53 | // Any compiler version from the 0.8 release (= 0.8.x)
54 | pragma solidity ^0.8.0;
55 | // Greater than version 0.7.6, less than version 0.8.4
56 | pragma solidity >0.7.6 <0.8.4;
57 | ```
58 |
59 | ### define a contract
60 | ```
61 | contract Score {
62 | // You will start writing your code here =)
63 | }
64 | ```
65 |
66 | ### variable in Solidity
67 |
68 | ```
69 | contract Score {
70 | uint score = 5;
71 | }
72 | ```
73 |
74 | ## Data types
75 |
76 | `bool` : The possible values are constants true and false.
77 |
78 | `Integers`
79 |
80 | `uint` : defines an unsigned integer of 256 bits by default.
81 | You can also specify the number of bits, by range of 8 bits. Here are some examples below:
82 |
83 |
84 |
85 | `int` : defines an signed integer of 256 bits by default.
86 |
87 | `Address` : Holds a 20 byte value (size of an Ethereum address).
88 |
89 | `address a = 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc;`
90 |
91 | ## Getter and Setter
92 | ` contract Score {
93 |
94 | uint score = 5;
95 |
96 | function getScore() returns (uint) {
97 |
98 | return score;
99 |
100 | }
101 |
102 | function setScore(uint new_score) {
103 |
104 | score = new_score;
105 |
106 | }
107 | } `
108 |
109 | ## Function visibility
110 |
111 |
112 | ## View vs Pure ?
113 | view functions can only read from the contract storage. They can’t modify the contract
114 | storage. Usually, you will use view for getters.
115 | pure functions can neither read nor modify the contract storage. They are only used
116 | for computation (like mathematical operations).
117 | Because our function getScore() only reads from the contract state, it is a view function.
118 | `
119 | function getScore() public view returns (uint) {
120 |
121 | return score;
122 |
123 | }
124 | `
125 |
126 | ## Extra Info
127 | Solidity provides a global variable msg , that refers to the address that interacts with the
128 | contract’s functions. The msg variables offers two associated fields:
129 |
130 | `msg.sender` : returns the address of the caller of the function.
131 | `msg.value` : returns the value in Wei of the amount of Ether sent to the function.
132 |
133 | ## modifiers
134 |
135 | A modifier is a special function that enables us to change the behaviour of
136 | functions in Solidity. It is mostly used to automatically check a condition before executing a
137 | function.
138 |
139 | `
140 |
141 | address owner;
142 |
143 | modifier onlyOwner {
144 |
145 | if (msg.sender == owner) {
146 |
147 | _;
148 |
149 | }
150 |
151 | }
152 |
153 | function setScore(uint new_score) public onlyOwner {
154 |
155 | score = new_score;
156 |
157 | }
158 |
159 | `
160 |
161 | The modifier works with the following flow:
162 | 1. Check that the address of the caller ( msg.sender ) is equal to owner address.
163 | 2. If 1) is true, it passes the check. The _; will be replaced by the function body where
164 | the modifier is attached.
165 | A modifier can receive arguments like functions. Here is an example of a modifier that
166 | requires the caller to send a specific amount of Ether.
167 |
168 | `
169 | modifier Fee(uint fee) {
170 |
171 | if (msg.value == fee) {
172 |
173 | _;
174 |
175 | }
176 |
177 | }
178 | `
179 |
180 | ## Constructor
181 |
182 | `
183 | contract Score {
184 |
185 | address owner;
186 |
187 | constructor() {
188 |
189 | owner = msg.sender;
190 |
191 | }
192 |
193 | } `
194 |
195 | ## Advance Data Types
196 |
197 | ### Mappings
198 |
199 | Mappings are another important complex data type used in Solidity. They are useful for
200 | association, such as associating an address with a balance or a score. You define a
201 | mapping in Solidity as follow:
202 |
203 | mapping(KeyType => ValueType) mapping_name;
204 |
205 |
206 |
207 | You can access the value associated with a key in a mapping by specifing the key name
208 | inside square brackets [] as follows: mapping_name[key] .
209 | Our smart contract will store a mapping of all the user’s addresses and their associated
210 | score. The function getUserScore(address _user) enables to retrieve the score
211 | associated to a specific user’s address.
212 |
213 | `
214 | mapping(address => uint) score_list;
215 |
216 | function getUserScore(address user) public view returns (uint) {
217 |
218 | return score_list[user];
219 |
220 | }
221 | `
222 |
223 | ### Arrays
224 |
225 | Arrays are also an important part of Solidity. You have two types of arrays ( T represents
226 | the data type and k the maximum number of elements):
227 | Fixed size array : T[k]
228 | Dynamic size array : T[]
229 |
230 | uint[] all_possible_number;
231 | uint[9] one_digit_number;
232 |
233 | In Solidity, arrays are ordered numerically. Array indices are zero based. So the index of the
234 | 1st element will be 0. You access an element in an array in the same way than you do for a
235 | mapping:
236 |
237 | ` uint my_score = score_list[owner]; `
238 |
239 | You can also used the following two methods to work with arrays:
240 | array_name.length : returns the number of elements the array holds.
241 | array_name.push(new_element) : adds a new element at the end of the array.
242 |
243 | ### Structs
244 |
245 | We can build our own datatypes by combining simpler datatypes together into more complex
246 | types using structs.
247 | We use the keyword struct, followed by the structure name , then the fields that make up
248 | the structure.
249 | For example:
250 |
251 | `
252 |
253 | struct Funder {
254 |
255 | address addr;
256 |
257 | uint amount;
258 |
259 | } `
260 |
261 | Here we have created a datatype called Funder, that is composed of an address and a uint.
262 | We can now declare a variable of that type
263 |
264 | Funder giver;
265 |
266 | and reference the elements using dot notation
267 |
268 | giver.addr = address (0xBA7283457B0A138890F21DE2ebCF1AfB9186A2EF);
269 | giver.amount = 2500;
270 |
271 | The size of the structure has to be finite, this imposes restrictions on the elements that can
272 | be included in the struct.
273 |
274 | ## For Reference
275 | [Solidity by example](https://solidity-by-example.org/)
276 |
277 |
278 |
279 |
280 |
281 |
282 |
--------------------------------------------------------------------------------