├── .gitattributes
├── src
├── react-app-env.d.ts
├── components
│ ├── sce.png
│ ├── logo.png
│ ├── discord.png
│ ├── telegram.png
│ ├── youtube.png
│ ├── logo-dark.png
│ ├── mode-dark.png
│ ├── mode-light.png
│ ├── Example.module.css
│ ├── SEO.tsx
│ ├── Header.module.css
│ ├── Footer.module.css
│ ├── mode-light.svg
│ ├── mode-dark.svg
│ ├── Example.tsx
│ ├── Header.tsx
│ ├── logo.svg
│ └── logo-dark.svg
├── pages
│ ├── structs
│ │ ├── StructDeclaration.sol
│ │ ├── StructImport.sol
│ │ ├── index.tsx
│ │ ├── index.md
│ │ └── Structs.sol
│ ├── enum
│ │ ├── EnumImport.sol
│ │ ├── EnumDeclaration.sol
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Enum.sol
│ ├── hacks
│ │ ├── NFT-multi-mint
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── NFTMultiMint.sol
│ │ ├── re-entrancy
│ │ │ ├── ReEntrancyGuard.sol
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── honeypot
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── randomness
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── Randomness.sol
│ │ ├── contract-size
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── ContractSize.sol
│ │ ├── accessing-private-data
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── block-timestamp-manipulation
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── BlockTimestamp.sol
│ │ ├── front-running
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── FrontRunning.sol
│ │ ├── overflow
│ │ │ ├── index.tsx
│ │ │ └── index.md
│ │ ├── delegatecall
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ └── Delegatecall_1.sol
│ │ ├── self-destruct
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ ├── PreventForceEther.sol
│ │ │ └── ForceEther.sol
│ │ ├── denial-of-service
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── PreventDenialOfService.sol
│ │ ├── signature-replay
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ └── SigReplay.sol
│ │ ├── phishing-with-tx-origin
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ └── TxOrigin.sol
│ │ └── hiding-malicious-code-with-external-contract
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ └── ExternalContract.sol
│ ├── app
│ │ ├── erc721
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── ether-wallet
│ │ │ ├── index.md
│ │ │ ├── EtherWallet.sol
│ │ │ └── index.tsx
│ │ ├── iterable-mapping
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── create2
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── merkle-tree
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── minimal-proxy
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── multi-delegatecall
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── upgradeable-proxy
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── deploy-any-contract
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── multi-call
│ │ │ ├── TestMultiCall.sol
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── MultiCall.sol
│ │ ├── multi-sig-wallet
│ │ │ ├── TestContract.sol
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── write-to-any-slot
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── Slot.sol
│ │ ├── bi-directional-payment-channel
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── crowd-fund
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── erc20
│ │ │ ├── MyToken.sol
│ │ │ ├── index.tsx
│ │ │ ├── IERC20.sol
│ │ │ ├── index.md
│ │ │ └── ERC20.sol
│ │ ├── dutch-auction
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── english-auction
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ └── uni-directional-payment-channel
│ │ │ ├── index.tsx
│ │ │ └── index.md
│ ├── defi
│ │ ├── constant-product-amm
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── chainlink-price-oracle
│ │ │ ├── index.md
│ │ │ ├── index.tsx
│ │ │ └── Chainlink.sol
│ │ ├── constant-sum-amm
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── uniswap-v2-add-remove-liquidity
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── uniswap-v2-optimal-one-sided-supply
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ ├── uniswap-v2
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ │ └── staking-rewards
│ │ │ ├── index.md
│ │ │ └── index.tsx
│ ├── hello-world
│ │ ├── index.md
│ │ ├── HelloWorld.sol
│ │ ├── index.tsx
│ │ └── index.html.ts
│ ├── if-else
│ │ ├── index.md
│ │ ├── IfElse.sol
│ │ └── index.tsx
│ ├── abi-decode
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── AbiDecode.sol
│ ├── try-catch
│ │ ├── index.md
│ │ └── index.tsx
│ ├── payable
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Payable.sol
│ ├── constants
│ │ ├── index.md
│ │ ├── Constants.sol
│ │ ├── index.tsx
│ │ └── index.html.ts
│ ├── first-app
│ │ ├── index.md
│ │ ├── Counter.sol
│ │ └── index.tsx
│ ├── signature
│ │ ├── index.md
│ │ └── index.tsx
│ ├── immutable
│ │ ├── index.md
│ │ ├── Immutable.sol
│ │ ├── index.tsx
│ │ └── index.html.ts
│ ├── primitives
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Primitives.sol
│ ├── function
│ │ ├── index.md
│ │ └── index.tsx
│ ├── ether-units
│ │ ├── index.md
│ │ ├── EtherUnits.sol
│ │ └── index.tsx
│ ├── import
│ │ ├── Foo.sol
│ │ ├── Import.sol
│ │ ├── index.tsx
│ │ └── index.md
│ ├── events
│ │ ├── index.md
│ │ ├── Events.sol
│ │ └── index.tsx
│ ├── super
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Super.sol
│ ├── constructor
│ ├── state-variables
│ │ ├── index.md
│ │ ├── SimpleStorage.sol
│ │ └── index.tsx
│ ├── new-contract
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── NewContract.sol
│ ├── delegatecall
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Delegatecall.sol
│ ├── function-modifier
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── FunctionModifier.sol
│ ├── shadowing-inherited-state-variables
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Shadow.sol
│ ├── function-selector
│ │ ├── FunctionSelector.sol
│ │ ├── index.tsx
│ │ └── index.md
│ ├── loop
│ │ ├── index.md
│ │ ├── Loop.sol
│ │ └── index.tsx
│ ├── view-and-pure-functions
│ │ ├── index.md
│ │ ├── ViewAndPureFunctions.sol
│ │ └── index.tsx
│ ├── mapping
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Mapping.sol
│ ├── call
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Call.sol
│ ├── hashing
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Keccak256.sol
│ ├── variables
│ │ ├── index.md
│ │ ├── Variables.sol
│ │ └── index.tsx
│ ├── calling-contract
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── CallingContract.sol
│ ├── interface
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Interface.sol
│ ├── library
│ │ ├── index.md
│ │ └── index.tsx
│ ├── gas
│ │ ├── Gas.sol
│ │ ├── index.tsx
│ │ └── index.md
│ ├── fallback
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Fallback.sol
│ ├── array
│ │ ├── index.md
│ │ ├── index.tsx
│ │ ├── ArrayReplaceFromEnd.sol
│ │ ├── ArrayRemoveByShifting.sol
│ │ └── Array.sol
│ ├── data-locations
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── DataLocations.sol
│ ├── inheritance
│ │ ├── index.md
│ │ ├── index.tsx
│ │ └── Inheritance.sol
│ ├── error
│ │ ├── index.tsx
│ │ ├── index.md
│ │ ├── Account.sol
│ │ └── Error.sol
│ ├── visibility
│ │ ├── index.tsx
│ │ └── index.md
│ ├── sending-ether
│ │ ├── index.tsx
│ │ ├── index.md
│ │ └── SendingEther.sol
│ ├── tests
│ │ └── echidna
│ │ │ ├── index.tsx
│ │ │ ├── index.md
│ │ │ └── TestEchidna.sol
│ └── index.module.css
├── App.module.css
├── index.tsx
└── App.tsx
├── public
├── favicon.ico
└── manifest.json
├── scripts
├── template
│ ├── index.html.ts.mustache
│ ├── routes.tsx.mustache
│ └── index.tsx.mustache
└── lib.ts
├── manifest.json
├── .prettierrc
├── .github
└── workflows
│ └── integrate.yml
├── .gitignore
├── tsconfig.json
├── README.md
├── LICENSE
└── package.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sol linguist-language=Solidity
2 |
--------------------------------------------------------------------------------
/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/components/sce.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/sce.png
--------------------------------------------------------------------------------
/src/components/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/logo.png
--------------------------------------------------------------------------------
/src/components/discord.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/discord.png
--------------------------------------------------------------------------------
/src/components/telegram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/telegram.png
--------------------------------------------------------------------------------
/src/components/youtube.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/youtube.png
--------------------------------------------------------------------------------
/src/components/logo-dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/logo-dark.png
--------------------------------------------------------------------------------
/src/components/mode-dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/mode-dark.png
--------------------------------------------------------------------------------
/src/components/mode-light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Web3DAO-CN/solidity-example/HEAD/src/components/mode-light.png
--------------------------------------------------------------------------------
/src/pages/structs/StructDeclaration.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | struct Todo {
5 | string text;
6 | bool completed;
7 | }
8 |
--------------------------------------------------------------------------------
/src/pages/enum/EnumImport.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | import "./EnumDeclaration.sol";
5 |
6 | contract Enum {
7 | Status public status;
8 | }
9 |
--------------------------------------------------------------------------------
/src/pages/hacks/NFT-multi-mint/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 科学家NFT批量抢购
3 | version: 0.8.10
4 | description: 通过工厂合约部署抢购合约批量铸造nft突破限制
5 | ---
6 |
7 | ### 科学家 NFT 批量抢购
8 |
9 | ```solidity
10 | {{{NFTMultiMint}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/app/erc721/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: ERC721
3 | version: 0.8.10
4 | description: Example of ERC721 non fungible token in Solidity
5 | ---
6 |
7 | Example of ERC721
8 |
9 | ```solidity
10 | {{{ERC721}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/defi/constant-product-amm/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Constant Product AMM
3 | version: 0.8.10
4 | description: Constant product AMM
5 | ---
6 |
7 | Constant product AMM `XY = K`
8 |
9 | ```solidity
10 | {{{CPAMM}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/scripts/template/index.html.ts.mustache:
--------------------------------------------------------------------------------
1 | // metadata
2 | export const version = "{{{version}}}"
3 | export const title = "{{{title}}}"
4 | export const description = "{{{description}}}"
5 |
6 | const html = `{{{html}}}`
7 |
8 | export default html
9 |
--------------------------------------------------------------------------------
/src/pages/defi/chainlink-price-oracle/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Chainlink Price Oracle
3 | version: 0.8.10
4 | description: Chainlink Price Oracle
5 | ---
6 |
7 | ### ETH / USD Price Oracle
8 |
9 | ```solidity
10 | {{{Chainlink}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/structs/StructImport.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | import "./StructDeclaration.sol";
5 |
6 | contract Todos {
7 | // An array of 'Todo' structs
8 | Todo[] public todos;
9 | }
10 |
--------------------------------------------------------------------------------
/src/pages/hello-world/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hello World
3 | version: 0.8.10
4 | description: Hello world in Solidity
5 | ---
6 |
7 | `pragma` specifies the compiler version of Solidity.
8 |
9 | ```solidity
10 | {{{HelloWorld}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/hello-world/HelloWorld.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | // compiler version must be greater than or equal to 0.8.10 and less than 0.9.0
3 | pragma solidity ^0.8.10;
4 |
5 | contract HelloWorld {
6 | string public greet = "Hello World!";
7 | }
8 |
--------------------------------------------------------------------------------
/src/pages/defi/constant-sum-amm/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Constant Sum AMM
3 | version: 0.8.10
4 | description: Constant sum AMM
5 | ---
6 |
7 | Constant sum AMM `X + Y = K`
8 |
9 | Tokens trade one to one.
10 |
11 | ```solidity
12 | {{{CSAMM}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/enum/EnumDeclaration.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 | // This is saved 'EnumDeclaration.sol'
4 |
5 | enum Status {
6 | Pending,
7 | Shipped,
8 | Accepted,
9 | Rejected,
10 | Canceled
11 | }
12 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2-add-remove-liquidity/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Uniswap V2 Add Remove Liquidity
3 | version: 0.8.10
4 | description: Uniswap V2 add remove liquidity
5 | ---
6 |
7 | ### Add / Remove Liquidity
8 |
9 | ```solidity
10 | {{{Liquidity}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/if-else/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: If / Else
3 | version: 0.8.10
4 | description: If / Else conditional statement in Solidity
5 | ---
6 |
7 | Solidity supports conditional statements `if`, `else if` and `else`.
8 |
9 | ```solidity
10 | {{{IfElse}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/abi-decode/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: ABI Decode
3 | version: 0.8.10
4 | description: ABI decode bytes
5 | ---
6 |
7 | `abi.encode` encodes data into `bytes`.
8 |
9 | `abi.decode` decodes `bytes` back into data.
10 |
11 | ```solidity
12 | {{{AbiDecode}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2-optimal-one-sided-supply/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Uniswap V2 Optimal One Sided Supply
3 | version: 0.8.10
4 | description: Uniswap V2 Optimal One Sided Supply
5 | ---
6 |
7 | ### Optimal One Sided Supply
8 |
9 | ```solidity
10 | {{{Optimal}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Uniswap V2 Swap
3 | version: 0.8.10
4 | description: Uniswap V2 swap
5 | ---
6 |
7 | ### Swap
8 |
9 | Swaps an exact amount of input tokens for as many output tokens as possible.
10 |
11 | ```solidity
12 | {{{Swap}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/try-catch/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Try Catch
3 | version: 0.8.10
4 | description: An example of try / catch in Solidity
5 | ---
6 |
7 | `try / catch` can only catch errors from external function calls and contract creation.
8 |
9 | ```solidity
10 | {{{TryCatch}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/payable/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Payable
3 | version: 0.8.10
4 | description: An example of how to use the keyword payable in Solidity
5 | ---
6 |
7 | Functions and addresses declared `payable` can receive `ether` into the contract.
8 |
9 | ```solidity
10 | {{{Payable}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/constants/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Constants
3 | version: 0.8.10
4 | description: Constant variables
5 | ---
6 |
7 | Constants are variables that cannot be modified.
8 |
9 | Their value is hard coded and using constants can save gas cost.
10 |
11 | ```solidity
12 | {{{Constants}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/first-app/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: First Application
3 | version: 0.8.10
4 | description: Example of smart contract in Solidity
5 | ---
6 |
7 | Here is a simple contract that you can get, increment and decrement the count store in this contract.
8 |
9 | ```solidity
10 | {{{Counter}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/signature/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Verifying Signature
3 | version: 0.8.10
4 | description: An example of how to verify signatures in Solidity
5 | ---
6 |
7 | Messages can be signed off chain and then verified on chain using a smart contract.
8 |
9 | ```solidity
10 | {{{Signature}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/app/ether-wallet/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Ether Wallet
3 | version: 0.8.10
4 | description: Simple example of wallet in Solidity
5 | ---
6 |
7 | An example of a basic wallet.
8 |
9 | - Anyone can send ETH.
10 | - Only the owner can withdraw.
11 |
12 | ```solidity
13 | {{{EtherWallet}}}
14 | ```
15 |
--------------------------------------------------------------------------------
/src/pages/app/iterable-mapping/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Iterable Mapping
3 | version: 0.8.10
4 | description: Iterable Mapping in Solidity
5 | ---
6 |
7 | You cannot iterate through a `mapping`. So here is an example of how to create an iterable `mapping`.
8 |
9 | ```solidity
10 | {{{IterableMapping}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/constants/Constants.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Constants {
5 | // coding convention to uppercase constant variables
6 | address public constant MY_ADDRESS = 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc;
7 | uint public constant MY_UINT = 123;
8 | }
9 |
--------------------------------------------------------------------------------
/src/pages/app/create2/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Precompute Contract Address with Create2
3 | version: 0.8.10
4 | description: Precompute contract address with create2
5 | ---
6 |
7 | Contract address can be precomputed, before the contract is deployed, using `create2`
8 |
9 | ```solidity
10 | {{{Create2}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/immutable/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Immutable
3 | version: 0.8.10
4 | description: Immutable variables
5 | ---
6 |
7 | Immutable variables are like constants. Values of immutable variables can be set inside the constructor but cannot be modified afterwards.
8 |
9 | ```solidity
10 | {{{Immutable}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/primitives/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Primitive Data Types
3 | version: 0.8.10
4 | description: Primitive data types
5 | ---
6 |
7 | Here we introduce you to some primitive data types available in Solidity.
8 |
9 | - `boolean`
10 | - `uint`
11 | - `int`
12 | - `address`
13 |
14 | ```solidity
15 | {{{Primitives}}}
16 | ```
17 |
--------------------------------------------------------------------------------
/src/pages/app/merkle-tree/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Merkle Tree
3 | version: 0.8.10
4 | description: Learn about Merkle tree in Solidity
5 | ---
6 |
7 | Merkle tree allows you to cryptographically prove that an element is contained
8 |
9 | in a set without revealing the entire set.
10 |
11 | ```solidity
12 | {{{MerkleTree}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/function/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Function
3 | version: 0.8.10
4 | description: Example of how to write functions in Solidity
5 | ---
6 |
7 | There are several ways to return outputs from a function.
8 |
9 | Public functions cannot accept certain data types as inputs or outputs
10 |
11 | ```solidity
12 | {{{Function}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/components/Example.module.css:
--------------------------------------------------------------------------------
1 | .component {
2 | /* NOTE -20px from .main in App.module.css */
3 | width: min(100vw - 20px, 1000px);
4 | }
5 | .content {
6 | margin-top: 15px;
7 | margin-bottom: 15px;
8 | }
9 | .prevNext {
10 | margin: 20px;
11 | display: flex;
12 | flex-direction: row;
13 | justify-content: space-between;
14 | }
15 |
--------------------------------------------------------------------------------
/src/pages/app/minimal-proxy/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Minimal Proxy Contract
3 | version: 0.8.10
4 | description: Deploy contracts cheaply with minimal proxy contract
5 | ---
6 |
7 | If you have a contract that will be deployed multiple times, use minimal proxy contract to deploy them cheaply.
8 |
9 | ```solidity
10 | {{{MinimalProxy}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/ether-units/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Ether and Wei
3 | version: 0.8.10
4 | description: An example of Ether and Wei in Solidity
5 | ---
6 |
7 | Transactions are paid with `ether`.
8 |
9 | Similar to how one dollar is equal to 100 cent, one `ether` is equal to 1018 `wei`.
10 |
11 | ```solidity
12 | {{{EtherUnits}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/app/multi-delegatecall/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Multi Delegatecall
3 | version: 0.8.10
4 | description: An example of contract to call multiple functions in a single transaction
5 | ---
6 |
7 | An example of calling multiple functions with a single transaction, using `delegatecall`.
8 |
9 | ```solidity
10 | {{{MultiDelegatecall}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/src/pages/hacks/re-entrancy/ReEntrancyGuard.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract ReEntrancyGuard {
5 | bool internal locked;
6 |
7 | modifier noReentrant() {
8 | require(!locked, "No re-entrancy");
9 | locked = true;
10 | _;
11 | locked = false;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/pages/import/Foo.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | struct Point {
5 | uint x;
6 | uint y;
7 | }
8 |
9 | error Unauthorized(address caller);
10 |
11 | function add(uint x, uint y) pure returns (uint) {
12 | return x + y;
13 | }
14 |
15 | contract Foo {
16 | string public name = "Foo";
17 | }
18 |
--------------------------------------------------------------------------------
/src/pages/events/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Events
3 | version: 0.8.10
4 | description: Example of how to emit events in Solidity
5 | ---
6 |
7 | `Events` allow logging to the Ethereum blockchain. Some use cases for events are:
8 |
9 | - Listening for events and updating user interface
10 | - A cheap form of storage
11 |
12 | ```solidity
13 | {{{Events}}}
14 | ```
15 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/pages/app/upgradeable-proxy/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Upgradeable Proxy
3 | version: 0.8.10
4 | description: Example of upgradeable proxy
5 | ---
6 |
7 | Example of upgradeable proxy contract. Never use this in production.
8 |
9 | This example shows how to use `delegatecall` and return data when `fallback` is called.
10 |
11 | ```solidity
12 | {{{UpgradeableProxy}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/ether-units/EtherUnits.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract EtherUnits {
5 | uint public oneWei = 1 wei;
6 | // 1 wei is equal to 1
7 | bool public isOneWei = 1 wei == 1;
8 |
9 | uint public oneEther = 1 ether;
10 | // 1 ether is equal to 10^18 wei
11 | bool public isOneEther = 1 ether == 1e18;
12 | }
13 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/pages/app/deploy-any-contract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Deploy Any Contract
3 | version: 0.8.10
4 | description: Deploy Any Contract
5 | ---
6 |
7 | Deploy any contract by calling `Proxy.deploy(bytes memory _code)`
8 |
9 | For this example, you can get the contract bytecodes by calling `Helper.getBytecode1` and `Helper.getBytecode2`
10 |
11 | ```solidity
12 | {{{Proxy}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/super/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Calling Parent Contracts
3 | version: 0.8.10
4 | description: An example of calling parent contracts in Solidity
5 | ---
6 |
7 | Parent contracts can be called directly, or by using the keyword `super`.
8 |
9 | By using the keyword `super`, all of the immediate parent contracts will be called.
10 |
11 | ```solidity
12 | {{{Super}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/constructor/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Constructor
3 | version: 0.8.10
4 | description: Learn how to initialize smart contracts in Solidity using a constructor
5 | ---
6 |
7 | A `constructor` is an optional function that is executed upon contract creation.
8 |
9 | Here are examples of how to pass arguments to `constructors`.
10 |
11 | ```solidity
12 | {{{Constructor}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/app/multi-call/TestMultiCall.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract TestMultiCall {
5 | function test(uint _i) external pure returns (uint) {
6 | return _i;
7 | }
8 |
9 | function getData(uint _i) external pure returns (bytes memory) {
10 | return abi.encodeWithSelector(this.test.selector, _i);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/pages/app/multi-sig-wallet/TestContract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract TestContract {
5 | uint public i;
6 |
7 | function callMe(uint j) public {
8 | i += j;
9 | }
10 |
11 | function getData() public pure returns (bytes memory) {
12 | return abi.encodeWithSignature("callMe(uint256)", 123);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/pages/immutable/Immutable.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Immutable {
5 | // coding convention to uppercase constant variables
6 | address public immutable MY_ADDRESS;
7 | uint public immutable MY_UINT;
8 |
9 | constructor(uint _myUint) {
10 | MY_ADDRESS = msg.sender;
11 | MY_UINT = _myUint;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "semi": false,
3 | "tabWidth": 2,
4 | "printWidth": 88,
5 | "overrides": [
6 | {
7 | "files": "*.sol",
8 | "options": {
9 | "printWidth": 88,
10 | "tabWidth": 4,
11 | "useTabs": false,
12 | "singleQuote": false,
13 | "bracketSpacing": false,
14 | "explicitTypes": "never"
15 | }
16 | }
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/pages/app/multi-call/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Multi Call
3 | version: 0.8.10
4 | description: An example of contract to aggregate multiple calls.
5 | ---
6 |
7 | An example of contract that aggregates multiple queries using a for loop and `staticcall`.
8 |
9 | ```solidity
10 | {{{MultiCall}}}
11 | ```
12 |
13 | Contract to test `MultiCall`
14 |
15 | ```solidity
16 | {{{TestMultiCall}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/hacks/honeypot/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Honeypot
3 | version: 0.8.10
4 | description: An example of honeypot in Solidity
5 | ---
6 |
7 | A honeypot is a trap to catch hackers.
8 |
9 | ### Vulnerability
10 |
11 | Combining two exploits, reentrancy and hiding malicious code, we can build a contract
12 |
13 | that will catch malicious users.
14 |
15 | ```solidity
16 | {{{HoneyPot}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/state-variables/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Reading and Writing to a State Variable
3 | version: 0.8.10
4 | description: Reading and Writing to a State Variable
5 | ---
6 |
7 | To write or update a state variable you need to send a transaction.
8 |
9 | On the other hand, you can read state variables, for free, without any transaction fee.
10 |
11 | ```solidity
12 | {{{SimpleStorage}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/new-contract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Contract that Creates other Contracts
3 | version: 0.8.10
4 | description: Learn how to create new contracts from inside of a contract with Solidity
5 | ---
6 |
7 | Contracts can be created by other contracts using the `new` keyword. Since 0.8.0, `new` keyword supports `create2` feature by specifying `salt` options.
8 |
9 | ```solidity
10 | {{{NewContract}}}
11 | ```
12 |
--------------------------------------------------------------------------------
/.github/workflows/integrate.yml:
--------------------------------------------------------------------------------
1 | name: Continuous Integration
2 |
3 | on:
4 | pull_request:
5 | branches: [gh-pages]
6 |
7 | jobs:
8 | test_pull_request:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v2
12 | - uses: actions/setup-node@v1
13 | with:
14 | node-version: 12
15 | - run: npm ci
16 | - run: npm test
17 | - run: npm run build
18 |
--------------------------------------------------------------------------------
/src/pages/app/write-to-any-slot/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Write to Any Slot
3 | version: 0.8.10
4 | description: Write to Any Slot
5 | ---
6 |
7 | Solidity storage is like an array of length 2^256.
8 | Each slot in the array can store 32 bytes.
9 |
10 | State variables define which slots will be used to store data.
11 |
12 | However using assembly, you can write to any slot.
13 |
14 | ```solidity
15 | {{{Slot}}}
16 | ```
17 |
--------------------------------------------------------------------------------
/src/components/SEO.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { Helmet } from "react-helmet"
3 |
4 | interface Props {
5 | title: string
6 | description: string
7 | }
8 |
9 | const SEO: React.FC = ({ title, description }) => {
10 | return (
11 |
12 | {title}
13 |
14 |
15 | )
16 | }
17 |
18 | export default SEO
19 |
--------------------------------------------------------------------------------
/src/pages/delegatecall/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Delegatecall
3 | version: 0.8.10
4 | description: Example of how to use deletegatecall in Solidity
5 | ---
6 |
7 | `delegatecall` is a low level function similar to `call`.
8 |
9 | When contract `A` executes `delegatecall` to contract `B`, `B`'s code is excuted
10 |
11 | with contract `A`'s storage, `msg.sender` and `msg.value`.
12 |
13 | ```solidity
14 | {{{Delegatecall}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/function-modifier/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Function Modifier
3 | version: 0.8.10
4 | description: Example of how to write function modifier in Solidity
5 | ---
6 |
7 | Modifiers are code that can be run before and / or after a function call.
8 |
9 | Modifiers can be used to:
10 |
11 | - Restrict access
12 | - Validate inputs
13 | - Guard against reentrancy hack
14 |
15 | ```solidity
16 | {{{FunctionModifier}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/shadowing-inherited-state-variables/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Shadowing Inherited State Variables
3 | version: 0.8.10
4 | description: An example of shadowing state variables by inheritance
5 | ---
6 |
7 | Unlike functions, state variables cannot be overridden by re-declaring it
8 | in the child contract.
9 |
10 | Let's learn how to correctly override inherited state variables.
11 |
12 | ```solidity
13 | {{{Shadow}}}
14 | ```
15 |
--------------------------------------------------------------------------------
/src/pages/function-selector/FunctionSelector.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract FunctionSelector {
5 | /*
6 | "transfer(address,uint256)"
7 | 0xa9059cbb
8 | "transferFrom(address,address,uint256)"
9 | 0x23b872dd
10 | */
11 | function getSelector(string calldata _func) external pure returns (bytes4) {
12 | return bytes4(keccak256(bytes(_func)));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/pages/loop/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: For and While Loop
3 | version: 0.8.10
4 | description: Example of for and while loop in Solidity
5 | ---
6 |
7 | Solidity supports `for`, `while`, and `do while` loops.
8 |
9 | Don't write loops that are unbounded as this can hit the gas limit, causing your transaction to fail.
10 |
11 | For the reason above, `while` and `do while` loops are rarely used.
12 |
13 | ```solidity
14 | {{{Loop}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/view-and-pure-functions/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: View and Pure Functions
3 | version: 0.8.10
4 | description: An example of view and pure functions in Solidity
5 | ---
6 |
7 | Getter functions can be declared `view` or `pure`.
8 |
9 | `View` function declares that no state will be changed.
10 |
11 | `Pure` function declares that no state variable will be changed or read.
12 |
13 | ```solidity
14 | {{{ViewAndPureFunctions}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/hacks/randomness/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Source of Randomness
3 | version: 0.8.10
4 | description: Blockchain is not a reliable source of randomness in Solidity
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | `blockhash` and `block.timestamp` are not reliable sources for randomness.
10 |
11 | ```solidity
12 | {{{Randomness}}}
13 | ```
14 |
15 | ### Preventative Techniques
16 |
17 | - Don't use `blockhash` and `block.timestamp` as source of randomness
18 |
--------------------------------------------------------------------------------
/src/pages/mapping/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Mapping
3 | version: 0.8.10
4 | description: Example of using mapping in Solidity
5 | ---
6 |
7 | Maps are created with the syntax `mapping(keyType => valueType)`.
8 |
9 | The `keyType` can be any built-in value type, bytes, string, or any contract.
10 |
11 | `valueType` can be any type including another mapping or an array.
12 |
13 | Mappings are not iterable.
14 |
15 | ```solidity
16 | {{{Mapping}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/hacks/contract-size/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Bypass Contract Size Check
3 | version: 0.8.10
4 | description: An example of bypassing contract size check
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | If an address is a contract then the size of code stored at the address will be greater than 0 right?
10 |
11 | Let's see how we can create a contract with code size returned by `extcodesize` equal to 0.
12 |
13 | ```solidity
14 | {{{ContractSize}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/app/bi-directional-payment-channel/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Bi-Directional Payment Channel
3 | version: 0.8.10
4 | description: An example of bi-directional payment channels in Solidity
5 | ---
6 |
7 | Bi-directional payment channels allow participants `Alice` and `Bob` to repeatedly transfer Ether off chain.
8 |
9 | Payments can go both ways, `Alice` pays `Bob` and `Bob` pays `Alice`.
10 |
11 | ```solidity
12 | {{{BiDirectionalPaymentChannel}}}
13 | ```
14 |
--------------------------------------------------------------------------------
/src/pages/call/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Call
3 | version: 0.8.10
4 | description: In Solidity call is a low level function to interact with other contracts
5 | ---
6 |
7 | `call` is a low level function to interact with other contracts.
8 |
9 | This is the recommended method to use when you're just sending Ether via calling the `fallback` function.
10 |
11 | However it is not the recommend way to call existing functions.
12 |
13 | ```solidity
14 | {{{Call}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/hashing/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hashing with Keccak256
3 | version: 0.8.10
4 | description: Example of hashing using Keccak256 in Solidity
5 | ---
6 |
7 | `keccak256` computes the Keccak-256 hash of the input.
8 |
9 | Some use cases are:
10 |
11 | - Creating a deterministic unique ID from a input
12 | - Commit-Reveal scheme
13 | - Compact cryptographic signature (by signing the hash instead of a larger input)
14 |
15 | ```solidity
16 | {{{Keccak256}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/variables/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Variables
3 | version: 0.8.10
4 | description: Local, state and global variables
5 | ---
6 |
7 | There are 3 types of variables in Solidity
8 |
9 | - **local**
10 | - declared inside a function
11 | - not stored on the blockchain
12 | - **state**
13 | - declared outside a function
14 | - stored on the blockchain
15 | - **global** (provides information about the blockchain)
16 |
17 | ```solidity
18 | {{{Variables}}}
19 | ```
20 |
--------------------------------------------------------------------------------
/src/pages/calling-contract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Calling Other Contract
3 | version: 0.8.10
4 | description: In Solidity, contract can call other contracts in several ways
5 | ---
6 |
7 | Contract can call other contracts in 2 ways.
8 |
9 | The easiest way to is to just call it, like `A.foo(x, y, z)`.
10 |
11 | Another way to call other contracts is to use the low-level `call`.
12 |
13 | This method is not recommended.
14 |
15 | ```solidity
16 | {{{CallingContract}}}
17 | ```
18 |
--------------------------------------------------------------------------------
/src/pages/interface/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Interface
3 | version: 0.8.10
4 | description: An example of interface in Solidity
5 | ---
6 |
7 | You can interact with other contracts by declaring an `Interface`.
8 |
9 | Interface
10 |
11 | - cannot have any functions implemented
12 | - can inherit from other interfaces
13 | - all declared functions must be external
14 | - cannot declare a constructor
15 | - cannot declare state variables
16 |
17 | ```solidity
18 | {{{Interface}}}
19 | ```
20 |
--------------------------------------------------------------------------------
/src/pages/view-and-pure-functions/ViewAndPureFunctions.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract ViewAndPure {
5 | uint public x = 1;
6 |
7 | // Promise not to modify the state.
8 | function addToX(uint y) public view returns (uint) {
9 | return x + y;
10 | }
11 |
12 | // Promise not to modify or read from the state.
13 | function add(uint i, uint j) public pure returns (uint) {
14 | return i + j;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/pages/library/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Library
3 | version: 0.8.10
4 | description: Example of how to write and use libraries in your Solidity code
5 | ---
6 |
7 | Libraries are similar to contracts, but you can't declare any state variable and
8 | you can't send ether.
9 |
10 | A library is embedded into the contract if all library functions are internal.
11 |
12 | Otherwise the library must be deployed and then linked before the contract is deployed.
13 |
14 | ```solidity
15 | {{{Library}}}
16 | ```
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | package-lock.json
8 |
9 | # testing
10 | /coverage
11 |
12 | # production
13 | /build
14 |
15 | # misc
16 | .DS_Store
17 | .env.local
18 | .env.development.local
19 | .env.test.local
20 | .env.production.local
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
26 | memo.js
27 | .vscode
28 | .eslintcache
29 | memo
30 | crytic-export
--------------------------------------------------------------------------------
/src/pages/gas/Gas.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Gas {
5 | uint public i = 0;
6 |
7 | // Using up all of the gas that you send causes your transaction to fail.
8 | // State changes are undone.
9 | // Gas spent are not refunded.
10 | function forever() public {
11 | // Here we run a loop until all of the gas are spent
12 | // and the transaction fails
13 | while (true) {
14 | i += 1;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/pages/first-app/Counter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Counter {
5 | uint public count;
6 |
7 | // Function to get the current count
8 | function get() public view returns (uint) {
9 | return count;
10 | }
11 |
12 | // Function to increment count by 1
13 | function inc() public {
14 | count += 1;
15 | }
16 |
17 | // Function to decrement count by 1
18 | function dec() public {
19 | count -= 1;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/pages/app/crowd-fund/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Crowd Fund
3 | version: 0.8.10
4 | description: An example of crowd funding contract
5 | ---
6 |
7 | Crowd fund ERC20 token
8 |
9 | 1. User creates a campaign.
10 | 2. Users can pledge, transferring their token to a campaign.
11 | 3. After the campaign ends, campaign creator can claim the funds if total amount pledged is more than the campaign goal.
12 | 4. Otherwise, campaign did not reach it's goal, users can withdraw their pledge.
13 |
14 | ```solidity
15 | {{{CrowdFund}}}
16 | ```
17 |
--------------------------------------------------------------------------------
/src/pages/state-variables/SimpleStorage.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract SimpleStorage {
5 | // State variable to store a number
6 | uint public num;
7 |
8 | // You need to send a transaction to write to a state variable.
9 | function set(uint _num) public {
10 | num = _num;
11 | }
12 |
13 | // You can read from a state variable without sending a transaction.
14 | function get() public view returns (uint) {
15 | return num;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/pages/defi/staking-rewards/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Staking Rewards
3 | version: 0.8.10
4 | description: Staking rewards contract based on Synthetix StakingRewards.sol
5 | ---
6 |
7 | This is a minimal example of a contract that rewards users for staking their token.
8 |
9 | Code is a stripped down version of Synthetix StakingRewards.sol
10 |
11 | ### Staking Rewards
12 |
13 | ```solidity
14 | {{{StakingRewards}}}
15 | ```
16 |
--------------------------------------------------------------------------------
/src/pages/events/Events.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Event {
5 | // Event declaration
6 | // Up to 3 parameters can be indexed.
7 | // Indexed parameters helps you filter the logs by the indexed parameter
8 | event Log(address indexed sender, string message);
9 | event AnotherLog();
10 |
11 | function test() public {
12 | emit Log(msg.sender, "Hello World!");
13 | emit Log(msg.sender, "Hello EVM!");
14 | emit AnotherLog();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/pages/hacks/accessing-private-data/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Accessing Private Data
3 | version: 0.8.10
4 | description: An example of accessing private data from a Solidity smart contract
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | All data on a smart contract can be read.
10 |
11 | Let's see how we can read `private` data. In the process you will learn how Solidity stores state variables.
12 |
13 | ```solidity
14 | {{{Vault}}}
15 | ```
16 |
17 | ### Preventative Techniques
18 |
19 | - Don't store sensitive information on the blockchain.
20 |
--------------------------------------------------------------------------------
/src/pages/import/Import.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | // import Foo.sol from current directory
5 | import "./Foo.sol";
6 |
7 | // import {symbol1 as alias, symbol2} from "filename";
8 | import {Unauthorized, add as func, Point} from "./Foo.sol";
9 |
10 | contract Import {
11 | // Initialize Foo.sol
12 | Foo public foo = new Foo();
13 |
14 | // Test Foo.sol by getting it's name.
15 | function getFooName() public view returns (string memory) {
16 | return foo.name();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/pages/fallback/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Fallback
3 | version: 0.8.10
4 | description: Example of how to use fallback in Solidity
5 | ---
6 |
7 | `fallback` is a function that does not take any arguments and does not return anything.
8 |
9 | It is executed either when
10 |
11 | - a function that does not exist is called or
12 | - Ether is sent directly to a contract but `receive()` does not exist or `msg.data` is not empty
13 |
14 | `fallback` has a 2300 gas limit when called by `transfer` or `send`.
15 |
16 | ```solidity
17 | {{{Fallback}}}
18 | ```
19 |
--------------------------------------------------------------------------------
/src/pages/app/erc20/MyToken.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.0.0/contracts/token/ERC20/ERC20.sol";
5 |
6 | contract MyToken is ERC20 {
7 | constructor(string memory name, string memory symbol) ERC20(name, symbol) {
8 | // Mint 100 tokens to msg.sender
9 | // Similar to how
10 | // 1 dollar = 100 cents
11 | // 1 token = 1 * (10 ** decimals)
12 | _mint(msg.sender, 100 * 10**uint(decimals()));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/pages/enum/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Enum
3 | version: 0.8.10
4 | description: Example of enums in Solidity
5 | ---
6 |
7 | Solidity supports enumerables and they are useful to model choice and keep track of state.
8 |
9 | Enums can be declared outside of a contract.
10 |
11 | ```solidity
12 | {{{Enum}}}
13 | ```
14 |
15 | ### Declaring and importing Enum
16 |
17 | File that the enum is declared in
18 |
19 | ```solidity
20 | {{{EnumDeclaration}}}
21 | ```
22 |
23 | File that imports the enum above
24 |
25 | ```solidity
26 | {{{EnumImport}}}
27 | ```
28 |
--------------------------------------------------------------------------------
/src/pages/array/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Array
3 | version: 0.8.10
4 | description: Learn about arrays in Solidity
5 | ---
6 |
7 | Array can have a compile-time fixed size or a dynamic size.
8 |
9 | ```solidity
10 | {{{Array}}}
11 | ```
12 |
13 | ### Examples of removing array element
14 |
15 | Remove array element by shifting elements from right to left
16 |
17 | ```solidity
18 | {{{ArrayRemoveByShifting}}}
19 | ```
20 |
21 | Remove array element by copying last element into to the place to remove
22 |
23 | ```solidity
24 | {{{ArrayReplaceFromEnd}}}
25 | ```
26 |
--------------------------------------------------------------------------------
/src/pages/app/dutch-auction/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Dutch Auction
3 | version: 0.8.10
4 | description: An example of Dutch auction in Solidity
5 | ---
6 |
7 | Dutch auction for NFT.
8 |
9 | ### Auction
10 |
11 | 1. Seller of NFT deploys this contract setting a starting price for the NFT.
12 | 2. Auction lasts for 7 days.
13 | 3. Price of NFT decreases over time.
14 | 4. Participants can buy by depositing ETH greater than the current price computed by the smart contract.
15 | 5. Auction ends when a buyer buys the NFT.
16 |
17 | ```solidity
18 | {{{DutchAuction}}}
19 | ```
20 |
--------------------------------------------------------------------------------
/src/App.module.css:
--------------------------------------------------------------------------------
1 | .component {
2 | display: flex;
3 | flex-direction: column;
4 | min-height: 100vh;
5 | }
6 |
7 | .main {
8 | display: flex;
9 | flex: 1;
10 | flex-direction: column;
11 | margin: auto;
12 | padding: 10px;
13 | /* align-items: center; */
14 | /* background-color: red; */
15 | }
16 |
17 | /* @media only screen and (max-width: 600px) {
18 | .main {
19 | margin: 0;
20 | }
21 | } */
22 |
23 | .footer {
24 | display: flex;
25 | flex-direction: column;
26 | align-items: center;
27 | padding-top: 10px;
28 | padding-bottom: 20px;
29 | }
30 |
--------------------------------------------------------------------------------
/src/pages/variables/Variables.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Variables {
5 | // State variables are stored on the blockchain.
6 | string public text = "Hello";
7 | uint public num = 123;
8 |
9 | function doSomething() public {
10 | // Local variables are not saved to the blockchain.
11 | uint i = 456;
12 |
13 | // Here are some global variables
14 | uint timestamp = block.timestamp; // Current block timestamp
15 | address sender = msg.sender; // address of the caller
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/pages/data-locations/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Data Locations - Storage, Memory and Calldata
3 | version: 0.8.10
4 | description: Data locations - storage, memory and calldata
5 | ---
6 |
7 | Variables are declared as either `storage`, `memory` or `calldata` to explicitly
8 | specify the location of the data.
9 |
10 | - `storage` - variable is a state variable (store on blockchain)
11 | - `memory` - variable is in memory and it exists while a function is being called
12 | - `calldata` - special data location that contains function arguments
13 |
14 | ```solidity
15 | {{{DataLocations}}}
16 | ```
17 |
--------------------------------------------------------------------------------
/scripts/template/routes.tsx.mustache:
--------------------------------------------------------------------------------
1 | {{#routes}}
2 | import {{{componentName}}} from "{{{importPath}}}"
3 | {{/routes}}
4 |
5 | interface Path {
6 | title: string
7 | path: string
8 | }
9 |
10 | interface Paths {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | interface Route {
16 | path: string
17 | component: React.FC
18 | breakingChanges?: boolean
19 | }
20 |
21 | const routes: Route[] = [
22 | {{#routes}}
23 | {
24 | path: "{{{routePath}}}",
25 | component: {{{componentName}}}
26 | },
27 | {{/routes}}
28 | ]
29 |
30 | export default routes
--------------------------------------------------------------------------------
/src/pages/app/ether-wallet/EtherWallet.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract EtherWallet {
5 | address payable public owner;
6 |
7 | constructor() {
8 | owner = payable(msg.sender);
9 | }
10 |
11 | receive() external payable {}
12 |
13 | function withdraw(uint _amount) external {
14 | require(msg.sender == owner, "caller is not owner");
15 | payable(msg.sender).transfer(_amount);
16 | }
17 |
18 | function getBalance() external view returns (uint) {
19 | return address(this).balance;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/pages/hacks/block-timestamp-manipulation/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Block Timestamp Manipulation
3 | version: 0.8.10
4 | description: An example of a Solidity contract vulnerable to block timestamp manipulation
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | `block.timestamp` can be manipulated by miners with the following constraints
10 |
11 | - it cannot be stamped with an earlier time than its parent
12 | - it cannot be too far in the future
13 |
14 | ```solidity
15 | {{{BlockTimestamp}}}
16 | ```
17 |
18 | ### Preventative Techniques
19 |
20 | - Don't use `block.timestamp` for a source of entropy and random number
21 |
--------------------------------------------------------------------------------
/src/pages/loop/Loop.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Loop {
5 | function loop() public {
6 | // for loop
7 | for (uint i = 0; i < 10; i++) {
8 | if (i == 3) {
9 | // Skip to next iteration with continue
10 | continue;
11 | }
12 | if (i == 5) {
13 | // Exit loop with break
14 | break;
15 | }
16 | }
17 |
18 | // while loop
19 | uint j;
20 | while (j < 10) {
21 | j++;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/pages/app/multi-sig-wallet/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Multi-Sig Wallet
3 | version: 0.8.10
4 | description: An example of multi-sig wallet in Solidity
5 | ---
6 |
7 | Let's create an multi-sig wallet. Here are the specifications.
8 |
9 | The wallet owners can
10 |
11 | - submit a transaction
12 | - approve and revoke approval of pending transcations
13 | - anyone can execute a transcation after enough owners has approved it.
14 |
15 | ```solidity
16 | {{{MultiSigWallet}}}
17 | ```
18 |
19 | Here is a contract to test sending transactions from the multi-sig wallet
20 |
21 | ```solidity
22 | {{{TestContract}}}
23 | ```
24 |
--------------------------------------------------------------------------------
/src/pages/hacks/front-running/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Front Running
3 | version: 0.8.10
4 | description: An example of a Solidity contract vulnerable to front running
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | Transactions take some time before they are mined. An attacker can watch the transaction pool
10 | and send a transaction, have it included in a block before the original transaction.
11 | This mechanism can be abused to re-order transactions to the attacker's advantage.
12 |
13 | ```solidity
14 | {{{FrontRunning}}}
15 | ```
16 |
17 | ### Preventative Techniques
18 |
19 | - use commit-reveal scheme
20 | - use submarine send
21 |
--------------------------------------------------------------------------------
/src/pages/inheritance/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Inheritance
3 | version: 0.8.10
4 | description: Example of inheritance in Solidity
5 | ---
6 |
7 | Solidity supports multiple inheritance. Contracts can inherit other contract by using the `is` keyword.
8 |
9 | Function that is going to be overridden by a child contract must be declared as `virtual`.
10 |
11 | Function that is going to override a parent function must use the keyword `override`.
12 |
13 | Order of inheritance is important.
14 |
15 | You have to list the parent contracts in the order from “most base-like” to “most derived”.
16 |
17 | ```solidity
18 | {{{Inheritance}}}
19 | ```
20 |
--------------------------------------------------------------------------------
/src/pages/array/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/call/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/enum/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/error/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/events/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/gas/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hashing/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/if-else/IfElse.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract IfElse {
5 | function foo(uint x) public pure returns (uint) {
6 | if (x < 10) {
7 | return 0;
8 | } else if (x < 20) {
9 | return 1;
10 | } else {
11 | return 2;
12 | }
13 | }
14 |
15 | function ternary(uint _x) public pure returns (uint) {
16 | // if (_x < 10) {
17 | // return 1;
18 | // }
19 | // return 2;
20 |
21 | // shorthand way to write if / else statement
22 | return _x < 10 ? 1 : 2;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/pages/if-else/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/import/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/library/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/loop/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/mapping/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/payable/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/structs/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/super/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/abi-decode/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/erc20/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/constants/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/constructor/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/delegatecall/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/ether-units/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/fallback/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/first-app/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/function/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hello-world/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/immutable/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/inheritance/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/interface/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/new-contract/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/primitives/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/signature/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/structs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Structs
3 | version: 0.8.10
4 | description: An example of how to use structs in Solidity
5 | ---
6 |
7 | You can define your own type by creating a `struct`.
8 |
9 | They are useful for grouping together related data.
10 |
11 | Structs can be declared outside of a contract and imported in another contract.
12 |
13 | ```solidity
14 | {{{Structs}}}
15 | ```
16 |
17 | ### Declaring and importing Struct
18 |
19 | File that the struct is declared in
20 |
21 | ```solidity
22 | {{{StructDeclaration}}}
23 | ```
24 |
25 | File that imports the struct above
26 |
27 | ```solidity
28 | {{{StructImport}}}
29 | ```
30 |
--------------------------------------------------------------------------------
/src/pages/try-catch/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/variables/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/visibility/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/scripts/template/index.tsx.mustache:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "{{{importPathToExample}}}"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/create2/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/crowd-fund/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/english-auction/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: English Auction
3 | version: 0.8.10
4 | description: An example of English auction in Solidity
5 | ---
6 |
7 | English auction for NFT.
8 |
9 | ### Auction
10 |
11 | 1. Seller of NFT deploys this contract.
12 | 2. Auction lasts for 7 days.
13 | 3. Participants can bid by depositing ETH greater than the current highest bidder.
14 | 4. All bidders can withdraw their bid if it is not the current highest bid.
15 |
16 | ### After the auction
17 |
18 | 1. Highest bidder becomes the new owner of NFT.
19 | 2. The seller receives the highest bid of ETH.
20 |
21 | ```solidity
22 | {{{EnglishAuction}}}
23 | ```
24 |
--------------------------------------------------------------------------------
/src/pages/app/erc721/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/multi-call/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/calling-contract/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/data-locations/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/function-modifier/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/function-selector/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/honeypot/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/overflow/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/re-entrancy/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Re-Entrancy
3 | version: 0.8.10
4 | description: An example of re-entrancy attack in Solidity
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | Let's say that contract `A` calls contract `B`.
10 |
11 | Reentracy exploit allows `B` to call back into `A` before `A` finishes execution.
12 |
13 | ```solidity
14 | {{{ReEntrancy}}}
15 | ```
16 |
17 | ### Preventative Techniques
18 |
19 | - Ensure all state changes happen before calling external contracts
20 | - Use function modifiers that prevent re-entrancy
21 |
22 | Here is a example of a re-entracy guard
23 |
24 | ```solidity
25 | {{{ReEntrancyGuard}}}
26 | ```
27 |
--------------------------------------------------------------------------------
/src/pages/sending-ether/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/state-variables/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/tests/echidna/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "module": "esnext",
16 | "moduleResolution": "node",
17 | "resolveJsonModule": true,
18 | "isolatedModules": true,
19 | "noEmit": true,
20 | "jsx": "react-jsx",
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": [
24 | "src"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/src/pages/app/dutch-auction/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/english-auction/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/ether-wallet/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/merkle-tree/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/minimal-proxy/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/contract-size/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/delegatecall/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/front-running/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/randomness/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/re-entrancy/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/self-destruct/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/deploy-any-contract/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/iterable-mapping/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/multi-delegatecall/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/multi-sig-wallet/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/upgradeable-proxy/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/write-to-any-slot/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/constant-sum-amm/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/staking-rewards/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/NFT-multi-mint/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/denial-of-service/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Denial of Service
3 | version: 0.8.10
4 | description: An example of denial of service hack in Solidity
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | There are many ways to attack a smart contract to make it unusable.
10 |
11 | One exploit we introduce here is denial of service by making the function to send Ether fail.
12 |
13 | ```solidity
14 | {{{DenialOfService}}}
15 | ```
16 |
17 | ### Preventative Techniques
18 |
19 | One way to prevent this is to allow the users to withdraw their Ether instead of sending it.
20 |
21 | Here is a example.
22 |
23 | ```solidity
24 | {{{PreventDenialOfService}}}
25 | ```
26 |
--------------------------------------------------------------------------------
/src/pages/hacks/denial-of-service/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/signature-replay/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/view-and-pure-functions/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/chainlink-price-oracle/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/constant-product-amm/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/accessing-private-data/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/phishing-with-tx-origin/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/bi-directional-payment-channel/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/block-timestamp-manipulation/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/shadowing-inherited-state-variables/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/app/uni-directional-payment-channel/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2-add-remove-liquidity/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/shadowing-inherited-state-variables/Shadow.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract A {
5 | string public name = "Contract A";
6 |
7 | function getName() public view returns (string memory) {
8 | return name;
9 | }
10 | }
11 |
12 | // Shadowing is disallowed in Solidity 0.6
13 | // This will not compile
14 | // contract B is A {
15 | // string public name = "Contract B";
16 | // }
17 |
18 | contract C is A {
19 | // This is the correct way to override inherited state variables.
20 | constructor() {
21 | name = "Contract C";
22 | }
23 |
24 | // C.getName returns "Contract C"
25 | }
26 |
--------------------------------------------------------------------------------
/src/pages/defi/uniswap-v2-optimal-one-sided-supply/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/hiding-malicious-code-with-external-contract/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import Example from "../../../components/Example"
3 | import html, { version, title, description } from "./index.html"
4 |
5 | interface Path {
6 | path: string
7 | title: string
8 | }
9 |
10 | interface Props {
11 | prev: Path | null
12 | next: Path | null
13 | }
14 |
15 | const ExamplePage: React.FC = ({ prev, next }) => {
16 | return (
17 |
25 | )
26 | }
27 |
28 | export default ExamplePage
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/self-destruct/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Self Destruct
3 | version: 0.8.10
4 | description: An example of how to delete your smart contract by calling seldestruct in Solidity
5 | ---
6 |
7 | Contracts can be deleted from the blockchain by calling `selfdestruct`.
8 |
9 | `selfdestruct` sends all remaining Ether stored in the contract to a
10 | designated address.
11 |
12 | ### Vulnerability
13 |
14 | A malicious contract can use `selfdestruct` to
15 | force sending Ether to any contract.
16 |
17 | ```solidity
18 | {{{ForceEther}}}
19 | ```
20 |
21 | ### Preventative Techniques
22 |
23 | Don't rely on `address(this).balance`
24 |
25 | ```solidity
26 | {{{PreventForceEther}}}
27 | ```
28 |
--------------------------------------------------------------------------------
/src/pages/visibility/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Visibility
3 | version: 0.8.10
4 | description: An example of external, internal, private and public functions in Solidity
5 | ---
6 |
7 | Functions and state variables have to declare whether they are accessible by other contracts.
8 |
9 | Functions can be declared as
10 |
11 | - `public` - any contract and account can call
12 | - `private` - only inside the contract that defines the function
13 | - `internal`- only inside contract that inherits an `internal` function
14 | - `external` - only other contracts and accounts can call
15 |
16 | State variables can be declared as `public`, `private`, or `internal` but not `external`.
17 |
18 | ```solidity
19 | {{{Visibility}}}
20 | ```
21 |
--------------------------------------------------------------------------------
/src/pages/app/multi-call/MultiCall.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract MultiCall {
5 | function multiCall(address[] calldata targets, bytes[] calldata data)
6 | external
7 | view
8 | returns (bytes[] memory)
9 | {
10 | require(targets.length == data.length, "target length != data length");
11 |
12 | bytes[] memory results = new bytes[](data.length);
13 |
14 | for (uint i; i < targets.length; i++) {
15 | (bool success, bytes memory result) = targets[i].staticcall(data[i]);
16 | require(success, "call failed");
17 | results[i] = result;
18 | }
19 |
20 | return results;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/pages/error/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Error
3 | version: 0.8.10
4 | description: Example of how to throw errors in Solidity
5 | ---
6 |
7 | An error will undo all changes made to the state during a transaction.
8 |
9 | You can throw an error by calling `require`, `revert` or `assert`.
10 |
11 | - `require` is used to validate inputs and conditions before execution.
12 | - `revert` is similar to `require`. See the code below for details.
13 | - `assert` is used to check for code that should never be false. Failing
14 | assertion probably means that there is a bug.
15 |
16 | Use custom error to save gas.
17 |
18 | ```solidity
19 | {{{Error}}}
20 | ```
21 |
22 | Here is another example
23 |
24 | ```solidity
25 | {{{Account}}}
26 | ```
27 |
--------------------------------------------------------------------------------
/src/components/Header.module.css:
--------------------------------------------------------------------------------
1 | .component {
2 | text-align: left;
3 | display: flex;
4 | flex-direction: row;
5 | align-items: center;
6 | }
7 | .component a {
8 | text-decoration: none;
9 | }
10 | .logo {
11 | width: 60px;
12 | }
13 | .light {
14 | width: 30px;
15 | cursor: pointer;
16 | margin: 0 20px 0 20px;
17 | }
18 | .dark {
19 | width: 30px;
20 | cursor: pointer;
21 | margin: 0 20px 0 20px;
22 | }
23 | .header {
24 | margin: 0;
25 | margin-right: auto;
26 | }
27 | .versions {
28 | margin-top: 10px;
29 | display: flex;
30 | flex-direction: row;
31 | align-items: center;
32 | font-weight: 500;
33 | font-size: 1rem;
34 | }
35 | .bar {
36 | margin-left: 5px;
37 | margin-right: 5px;
38 | }
39 | .version {
40 | margin-right: 5px;
41 | }
42 |
--------------------------------------------------------------------------------
/src/pages/hacks/overflow/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Arithmetic Overflow and Underflow
3 | version: 0.8.10
4 | description: An example of hacking Solidity with arithmetic overflow / underflow
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | ##### Solidity < 0.8
10 |
11 | Integers in Solidity overflow / underflow without any errors
12 |
13 | ##### Solidity >= 0.8
14 |
15 | Default behaviour of Solidity 0.8 for overflow / underflow is to throw an error.
16 |
17 | ```solidity
18 | {{{Overflow}}}
19 | ```
20 |
21 | ### Preventative Techniques
22 |
23 | - Use SafeMath to will prevent arithmetic overflow and underflow
24 |
25 | - Solidity 0.8 defaults to throwing an error for overflow / underflow
26 |
--------------------------------------------------------------------------------
/src/pages/hacks/self-destruct/PreventForceEther.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract EtherGame {
5 | uint public targetAmount = 3 ether;
6 | uint public balance;
7 | address public winner;
8 |
9 | function deposit() public payable {
10 | require(msg.value == 1 ether, "You can only send 1 Ether");
11 |
12 | balance += msg.value;
13 | require(balance <= targetAmount, "Game is over");
14 |
15 | if (balance == targetAmount) {
16 | winner = msg.sender;
17 | }
18 | }
19 |
20 | function claimReward() public {
21 | require(msg.sender == winner, "Not winner");
22 |
23 | (bool sent, ) = msg.sender.call{value: balance}("");
24 | require(sent, "Failed to send Ether");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/components/Footer.module.css:
--------------------------------------------------------------------------------
1 | .component {
2 | margin: 15px;
3 | color: var(--color);
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | }
8 | .row {
9 | display: flex;
10 | flex-direction: row;
11 | align-items: center;
12 | }
13 | .row .bar {
14 | margin-left: 5px;
15 | margin-right: 5px;
16 | }
17 | .row a,
18 | .row a:visited {
19 | color: var(--link-color);
20 | }
21 | .khan {
22 | margin-left: 10px;
23 | }
24 | .social {
25 | display: flex;
26 | flex-direction: row;
27 | align-items: center;
28 | }
29 | .sce {
30 | width: 30px;
31 | margin: 5px;
32 | border-radius: 4px;
33 | }
34 | .telegram {
35 | width: 30px;
36 | margin: 5px;
37 | }
38 | .discord {
39 | width: 30px;
40 | margin: 5px;
41 | }
42 | .youTube {
43 | width: 30px;
44 | margin: 5px;
45 | }
46 |
--------------------------------------------------------------------------------
/src/pages/index.module.css:
--------------------------------------------------------------------------------
1 | .component {
2 | /* set width for auto-margin to be same for 0.5 and 0.6 home page */
3 | width: 420px;
4 | }
5 | .component ul {
6 | list-style: none;
7 | padding: 0;
8 | }
9 | .updates {
10 | padding: 5px;
11 | padding-left: 15px;
12 | border-radius: 5px;
13 | }
14 | .category {
15 | color: var(--link-color);
16 | }
17 | .listItem {
18 | display: flex;
19 | flex-direction: row;
20 | align-items: center;
21 | margin-top: 10px;
22 | margin-bottom: 10px;
23 | white-space: nowrap;
24 | }
25 | .label {
26 | margin-left: 10px;
27 | }
28 | .header a {
29 | text-decoration: none;
30 | }
31 | .youTube {
32 | display: flex;
33 | flex-direction: row;
34 | align-items: center;
35 | margin: 10px 0 10px 0;
36 | }
37 | .youTubeLogo {
38 | width: 30px;
39 | padding-right: 10px;
40 | }
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Memo
2 |
3 | ```shell
4 | ## Deploy ##
5 | # md to react
6 | npx ts-node --project ./scripts/tsconfig.json scripts/md-to-react.ts src/pages/array
7 |
8 | # md to react all pages
9 | find src/pages -type d -not -path "*/__snapshots__" -exec npx ts-node --project ./scripts/tsconfig.json scripts/md-to-react.ts {} \;
10 |
11 | # build routes
12 | npx ts-node --project ./scripts/tsconfig.json scripts/build-routes.ts
13 |
14 | # deploy
15 | npm run deploy
16 |
17 | ## Compile Solidity ##
18 | solc-select install 0.8.10
19 | solc-select use 0.8.10
20 |
21 | # compile single file
22 | solc src/pages/hello-world/HelloWorld.sol
23 |
24 | # find and compile sol
25 | find src/pages/hacks -name "*.sol" solc {} \;
26 |
27 | ## Mics ##
28 | # rename files
29 | find . -type f -name "index.test.js" -exec sh -c 'mv "$0" "${0%.test.js}.test.tsx"' {} \;
30 | ```
31 |
--------------------------------------------------------------------------------
/src/pages/hacks/denial-of-service/PreventDenialOfService.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract KingOfEther {
5 | address public king;
6 | uint public balance;
7 | mapping(address => uint) public balances;
8 |
9 | function claimThrone() external payable {
10 | require(msg.value > balance, "Need to pay more to become the king");
11 |
12 | balances[king] += balance;
13 |
14 | balance = msg.value;
15 | king = msg.sender;
16 | }
17 |
18 | function withdraw() public {
19 | require(msg.sender != king, "Current king cannot withdraw");
20 |
21 | uint amount = balances[msg.sender];
22 | balances[msg.sender] = 0;
23 |
24 | (bool sent, ) = msg.sender.call{value: amount}("");
25 | require(sent, "Failed to send Ether");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/pages/hacks/signature-replay/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Signature Replay
3 | version: 0.8.10
4 | description: An example of a contract vulnerable to signature replay attack
5 | ---
6 |
7 | Signing messages off-chain and having a contract that requires that signature before executing
8 | a function is a useful technique.
9 |
10 | For example this technique is used to:
11 |
12 | - reduce number of transaction on chain
13 | - gas-less transaction, called `meta transaction`
14 |
15 | ### Vulnerability
16 |
17 | Same signature can be used multiple times to execute a function. This can be harmful
18 | if the signer's intention was to approve a transaction once.
19 |
20 | ```solidity
21 | {{{SigReplay}}}
22 | ```
23 |
24 | ### Preventative Techniques
25 |
26 | Sign messages with `nonce` and address of the contract.
27 |
28 | ```solidity
29 | {{{PreventSigReplay}}}
30 | ```
31 |
--------------------------------------------------------------------------------
/src/pages/function-selector/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Function Selector
3 | version: 0.8.10
4 | description: Example of how function selectors are computed
5 | ---
6 |
7 | When a function is called, the first 4 bytes of `calldata` specifies which function to call.
8 |
9 | This 4 bytes is called a function selector.
10 |
11 | Take for example, this code below. It uses `call` to execute `transfer` on a contract at the address `addr`.
12 |
13 | ```solidity
14 | addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123))
15 | ```
16 |
17 | The first 4 bytes returned from `abi.encodeWithSignature(....)` is the function selector.
18 |
19 | Perhaps you can save a tiny amount of gas if you precompute and inline the function selector in your code?
20 |
21 | Here is how the function selector is computed.
22 |
23 | ```solidity
24 | {{{FunctionSelector}}}
25 | ```
26 |
--------------------------------------------------------------------------------
/src/pages/delegatecall/Delegatecall.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | // NOTE: Deploy this contract first
5 | contract B {
6 | // NOTE: storage layout must be the same as contract A
7 | uint public num;
8 | address public sender;
9 | uint public value;
10 |
11 | function setVars(uint _num) public payable {
12 | num = _num;
13 | sender = msg.sender;
14 | value = msg.value;
15 | }
16 | }
17 |
18 | contract A {
19 | uint public num;
20 | address public sender;
21 | uint public value;
22 |
23 | function setVars(address _contract, uint _num) public payable {
24 | // A's storage is set, B is not modified.
25 | (bool success, bytes memory data) = _contract.delegatecall(
26 | abi.encodeWithSignature("setVars(uint256)", _num)
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/pages/app/uni-directional-payment-channel/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Uni-Directional Payment Channel
3 | version: 0.8.10
4 | description: An example of uni-directional payment channels in Solidity
5 | ---
6 |
7 | Payment channels allow participants to repeatedly transfer Ether off chain.
8 |
9 | Here is how this contract is used:
10 |
11 | - `Alice` deploys the contract, funding it with some Ether.
12 | - `Alice` authorizes a payment by signing a message (off chain) and sends the signature to `Bob`.
13 | - `Bob` claims his payment by presenting the signed message to the smart contract.
14 | - If `Bob` does not claim his payment, `Alice` get her Ether back after the contract expires
15 |
16 | This is called a uni-directional payment channel since the payment can go only in a single direction from `Alice` to `Bob`.
17 |
18 | ```solidity
19 | {{{UniDirectionalPaymentChannel}}}
20 | ```
21 |
--------------------------------------------------------------------------------
/src/pages/hacks/hiding-malicious-code-with-external-contract/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Hiding Malicious Code with External Contract
3 | version: 0.8.10
4 | description: An example of exploit where malicious code is hidden in an external contract in Solidity
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | In Solidity any address can be casted into specific contract,
10 | even if the contract at the address is not the one being casted.
11 |
12 | This can be exploited to hide malicious code. Let's see how.
13 |
14 | ```solidity
15 | {{{ExternalContract}}}
16 | ```
17 |
18 | ### Preventative Techniques
19 |
20 | - Initialize a new contract inside the constructor
21 | - Make the address of external contract `public` so that the code of the
22 | external contract can be reviewed
23 |
24 | ```solidity
25 | Bar public bar;
26 |
27 | constructor() public {
28 | bar = new Bar();
29 | }
30 | ```
31 |
--------------------------------------------------------------------------------
/src/pages/gas/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Gas
3 | version: 0.8.10
4 | description: Example of gas and gas limit in Solidity
5 | ---
6 |
7 | ### How much `ether` do you need to pay for a transaction?
8 |
9 | You pay `gas spent * gas price` amount of `ether`, where
10 |
11 | - `gas` is a unit of computation
12 | - `gas spent` is the total amount of `gas` used in a transaction
13 | - `gas price` is how much `ether` you are willing to pay per `gas`
14 |
15 | Transactions with higher gas price have higher priority to be included in a block.
16 |
17 | Unspent gas will be refunded.
18 |
19 | ### Gas Limit
20 |
21 | There are 2 upper bounds to the amount of gas you can spend
22 |
23 | - `gas limit` (max amount of gas you're willing to use for your transaction, set by you)
24 | - `block gas limit` (max amount of gas allowed in a block, set by the network)
25 |
26 | ```solidity
27 | {{{Gas}}}
28 | ```
29 |
--------------------------------------------------------------------------------
/src/pages/hacks/delegatecall/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Delegatecall
3 | version: 0.8.10
4 | description: An example of exploits using delegatecall in Solidity
5 | ---
6 |
7 | ### Vulnerability
8 |
9 | `delegatecall` is tricky to use and wrong usage or incorrect understanding
10 | can lead to devastating results.
11 |
12 | You must keep 2 things in mind when using `delegatecall`
13 |
14 | 1. `delegatecall` preserves context (storage, caller, etc...)
15 | 2. storage layout must be the same for the contract calling `delegatecall` and the contract getting called
16 |
17 | ```solidity
18 | {{{Delegatecall_1}}}
19 | ```
20 |
21 | Here is another example.
22 |
23 | You will need to understand how Solidity stores
24 | state variables before you can understand this exploit.
25 |
26 | ```solidity
27 | {{{Delegatecall_2}}}
28 | ```
29 |
30 | ### Preventative Techniques
31 |
32 | - Use stateless `Library`
33 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { hydrate, render } from "react-dom"
3 | import "./index.css"
4 | import { Provider as AppContextProvider } from "./contexts/AppContext"
5 | import App from "./App"
6 | import * as serviceWorker from "./serviceWorker"
7 |
8 | const rootElement = document.getElementById("root")
9 | // @ts-ignore
10 | if (rootElement.hasChildNodes()) {
11 | hydrate(
12 |
13 |
14 | ,
15 | rootElement
16 | )
17 | } else {
18 | render(
19 |
20 |
21 | ,
22 | rootElement
23 | )
24 | }
25 |
26 | // If you want your app to work offline and load faster, you can change
27 | // unregister() to register() below. Note this comes with some pitfalls.
28 | // Learn more about service workers: http://bit.ly/CRA-PWA
29 | serviceWorker.unregister()
30 |
--------------------------------------------------------------------------------
/src/pages/hacks/phishing-with-tx-origin/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Phishing with tx.origin
3 | version: 0.8.10
4 | description: An example of phishing with tx.origin in Solidity
5 | ---
6 |
7 | ### What's the difference between `msg.sender` and `tx.origin`?
8 |
9 | If contract A calls B, and B calls C, in C `msg.sender` is B and `tx.origin` is A.
10 |
11 | ### Vulnerability
12 |
13 | A malicious contract can deceive the owner of a contract into calling a
14 | function that only the owner should be able to call.
15 |
16 | ```solidity
17 | {{{TxOrigin}}}
18 | ```
19 |
20 | ### Preventative Techniques
21 |
22 | Use `msg.sender` instead of `tx.origin`
23 |
24 | ```solidity
25 | function transfer(address payable _to, uint256 _amount) public {
26 | require(msg.sender == owner, "Not owner");
27 |
28 | (bool sent, ) = _to.call.value(_amount)("");
29 | require(sent, "Failed to send Ether");
30 | }
31 |
32 | ```
33 |
--------------------------------------------------------------------------------
/src/pages/abi-decode/AbiDecode.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract AbiDecode {
5 | struct MyStruct {
6 | string name;
7 | uint[2] nums;
8 | }
9 |
10 | function encode(
11 | uint x,
12 | address addr,
13 | uint[] calldata arr,
14 | MyStruct calldata myStruct
15 | ) external pure returns (bytes memory) {
16 | return abi.encode(x, addr, arr, myStruct);
17 | }
18 |
19 | function decode(bytes calldata data)
20 | external
21 | pure
22 | returns (
23 | uint x,
24 | address addr,
25 | uint[] memory arr,
26 | MyStruct memory myStruct
27 | )
28 | {
29 | // (uint x, address addr, uint[] memory arr, MyStruct myStruct) = ...
30 | (x, addr, arr, myStruct) = abi.decode(data, (uint, address, uint[], MyStruct));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/pages/app/erc20/IERC20.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol
5 | interface IERC20 {
6 | function totalSupply() external view returns (uint);
7 |
8 | function balanceOf(address account) external view returns (uint);
9 |
10 | function transfer(address recipient, uint amount) external returns (bool);
11 |
12 | function allowance(address owner, address spender) external view returns (uint);
13 |
14 | function approve(address spender, uint amount) external returns (bool);
15 |
16 | function transferFrom(
17 | address sender,
18 | address recipient,
19 | uint amount
20 | ) external returns (bool);
21 |
22 | event Transfer(address indexed from, address indexed to, uint value);
23 | event Approval(address indexed owner, address indexed spender, uint value);
24 | }
25 |
--------------------------------------------------------------------------------
/src/pages/calling-contract/CallingContract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Callee {
5 | uint public x;
6 | uint public value;
7 |
8 | function setX(uint _x) public returns (uint) {
9 | x = _x;
10 | return x;
11 | }
12 |
13 | function setXandSendEther(uint _x) public payable returns (uint, uint) {
14 | x = _x;
15 | value = msg.value;
16 |
17 | return (x, value);
18 | }
19 | }
20 |
21 | contract Caller {
22 | function setX(Callee _callee, uint _x) public {
23 | uint x = _callee.setX(_x);
24 | }
25 |
26 | function setXFromAddress(address _addr, uint _x) public {
27 | Callee callee = Callee(_addr);
28 | callee.setX(_x);
29 | }
30 |
31 | function setXandSendEther(Callee _callee, uint _x) public payable {
32 | (uint x, uint value) = _callee.setXandSendEther{value: msg.value}(_x);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/pages/fallback/Fallback.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Fallback {
5 | event Log(uint gas);
6 |
7 | // Fallback function must be declared as external.
8 | fallback() external payable {
9 | // send / transfer (forwards 2300 gas to this fallback function)
10 | // call (forwards all of the gas)
11 | emit Log(gasleft());
12 | }
13 |
14 | // Helper function to check the balance of this contract
15 | function getBalance() public view returns (uint) {
16 | return address(this).balance;
17 | }
18 | }
19 |
20 | contract SendToFallback {
21 | function transferToFallback(address payable _to) public payable {
22 | _to.transfer(msg.value);
23 | }
24 |
25 | function callFallback(address payable _to) public payable {
26 | (bool sent, ) = _to.call{value: msg.value}("");
27 | require(sent, "Failed to send Ether");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/pages/hello-world/index.html.ts:
--------------------------------------------------------------------------------
1 | // metadata
2 | export const version = "0.8.10"
3 | export const title = "Hello World"
4 | export const description = "Hello world in Solidity"
5 |
6 | const html = `
pragma specifies the compiler version of Solidity.
7 |
// SPDX-License-Identifier: MIT
8 | // compiler version must be greater than or equal to 0.8.10 and less than 0.9.0
9 | pragmasolidity ^0.8.10;
10 |
11 | contractHelloWorld{
12 | stringpublic greet ="Hello World!";
13 | }
14 |
15 | `
16 |
17 | export default html
18 |
--------------------------------------------------------------------------------
/src/pages/array/ArrayReplaceFromEnd.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract ArrayReplaceFromEnd {
5 | uint[] public arr;
6 |
7 | // Deleting an element creates a gap in the array.
8 | // One trick to keep the array compact is to
9 | // move the last element into the place to delete.
10 | function remove(uint index) public {
11 | // Move the last element into the place to delete
12 | arr[index] = arr[arr.length - 1];
13 | // Remove the last element
14 | arr.pop();
15 | }
16 |
17 | function test() public {
18 | arr = [1, 2, 3, 4];
19 |
20 | remove(1);
21 | // [1, 4, 3]
22 | assert(arr.length == 3);
23 | assert(arr[0] == 1);
24 | assert(arr[1] == 4);
25 | assert(arr[2] == 3);
26 |
27 | remove(2);
28 | // [1, 4]
29 | assert(arr.length == 2);
30 | assert(arr[0] == 1);
31 | assert(arr[1] == 4);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/pages/error/Account.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Account {
5 | uint public balance;
6 | uint public constant MAX_UINT = 2**256 - 1;
7 |
8 | function deposit(uint _amount) public {
9 | uint oldBalance = balance;
10 | uint newBalance = balance + _amount;
11 |
12 | // balance + _amount does not overflow if balance + _amount >= balance
13 | require(newBalance >= oldBalance, "Overflow");
14 |
15 | balance = newBalance;
16 |
17 | assert(balance >= oldBalance);
18 | }
19 |
20 | function withdraw(uint _amount) public {
21 | uint oldBalance = balance;
22 |
23 | // balance - _amount does not underflow if balance >= _amount
24 | require(balance >= _amount, "Underflow");
25 |
26 | if (balance < _amount) {
27 | revert("Underflow");
28 | }
29 |
30 | balance -= _amount;
31 |
32 | assert(balance <= oldBalance);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/pages/sending-ether/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Sending Ether (transfer, send, call)
3 | version: 0.8.10
4 | description: An example of sending Ether in Solidity
5 | ---
6 |
7 | ### How to send Ether?
8 |
9 | You can send Ether to other contracts by
10 |
11 | - `transfer` (2300 gas, throws error)
12 | - `send` (2300 gas, returns bool)
13 | - `call` (forward all gas or set gas, returns bool)
14 |
15 | ### How to receive Ether?
16 |
17 | A contract receiving Ether must have at least one of the functions below
18 |
19 | - `receive() external payable`
20 | - `fallback() external payable`
21 |
22 | `receive()` is called if `msg.data` is empty, otherwise `fallback()` is called.
23 |
24 | ### Which method should you use?
25 |
26 | `call` in combination with re-entrancy guard is the recommended method to use after December 2019.
27 |
28 | Guard against re-entrancy by
29 |
30 | - making all state changes before calling other contracts
31 | - using re-entrancy guard modifier
32 |
33 | ```solidity
34 | {{{SendingEther}}}
35 | ```
36 |
--------------------------------------------------------------------------------
/src/pages/import/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Import
3 | version: 0.8.10
4 | description: Learn how to import other Solidity files
5 | ---
6 |
7 | You can import local and external files in Solidity.
8 |
9 | ### Local
10 |
11 | Here is our folder structure.
12 |
13 | ```
14 | ├── Import.sol
15 | └── Foo.sol
16 | ```
17 |
18 | Foo.sol
19 |
20 | ```solidity
21 | {{{Foo}}}
22 | ```
23 |
24 | Import.sol
25 |
26 | ```solidity
27 | {{{Import}}}
28 | ```
29 |
30 | ### External
31 |
32 | You can also import from [GitHub](https://github.com) by simply copying the url
33 |
34 | ```solidity
35 | // https://github.com/owner/repo/blob/branch/path/to/Contract.sol
36 | import "https://github.com/owner/repo/blob/branch/path/to/Contract.sol";
37 |
38 | // Example import ECDSA.sol from openzeppelin-contract repo, release-v4.5 branch
39 | // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.5/contracts/utils/cryptography/ECDSA.sol
40 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.5/contracts/utils/cryptography/ECDSA.sol";
41 |
42 | ```
43 |
--------------------------------------------------------------------------------
/src/pages/enum/Enum.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Enum {
5 | // Enum representing shipping status
6 | enum Status {
7 | Pending,
8 | Shipped,
9 | Accepted,
10 | Rejected,
11 | Canceled
12 | }
13 |
14 | // Default value is the first element listed in
15 | // definition of the type, in this case "Pending"
16 | Status public status;
17 |
18 | // Returns uint
19 | // Pending - 0
20 | // Shipped - 1
21 | // Accepted - 2
22 | // Rejected - 3
23 | // Canceled - 4
24 | function get() public view returns (Status) {
25 | return status;
26 | }
27 |
28 | // Update status by passing uint into input
29 | function set(Status _status) public {
30 | status = _status;
31 | }
32 |
33 | // You can update to a specific enum like this
34 | function cancel() public {
35 | status = Status.Canceled;
36 | }
37 |
38 | // delete resets the enum to its first value, 0
39 | function reset() public {
40 | delete status;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/pages/array/ArrayRemoveByShifting.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract ArrayRemoveByShifting {
5 | // [1, 2, 3] -- remove(1) --> [1, 3, 3] --> [1, 3]
6 | // [1, 2, 3, 4, 5, 6] -- remove(2) --> [1, 2, 4, 5, 6, 6] --> [1, 2, 4, 5, 6]
7 | // [1, 2, 3, 4, 5, 6] -- remove(0) --> [2, 3, 4, 5, 6, 6] --> [2, 3, 4, 5, 6]
8 | // [1] -- remove(0) --> [1] --> []
9 |
10 | uint[] public arr;
11 |
12 | function remove(uint _index) public {
13 | require(_index < arr.length, "index out of bound");
14 |
15 | for (uint i = _index; i < arr.length - 1; i++) {
16 | arr[i] = arr[i + 1];
17 | }
18 | arr.pop();
19 | }
20 |
21 | function test() external {
22 | arr = [1, 2, 3, 4, 5];
23 | remove(2);
24 | // [1, 2, 4, 5]
25 | assert(arr[0] == 1);
26 | assert(arr[1] == 2);
27 | assert(arr[2] == 4);
28 | assert(arr[3] == 5);
29 | assert(arr.length == 4);
30 |
31 | arr = [1];
32 | remove(0);
33 | // []
34 | assert(arr.length == 0);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Tasuku Nakamura
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/pages/data-locations/DataLocations.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract DataLocations {
5 | uint[] public arr;
6 | mapping(uint => address) map;
7 | struct MyStruct {
8 | uint foo;
9 | }
10 | mapping(uint => MyStruct) myStructs;
11 |
12 | function f() public {
13 | // call _f with state variables
14 | _f(arr, map, myStructs[1]);
15 |
16 | // get a struct from a mapping
17 | MyStruct storage myStruct = myStructs[1];
18 | // create a struct in memory
19 | MyStruct memory myMemStruct = MyStruct(0);
20 | }
21 |
22 | function _f(
23 | uint[] storage _arr,
24 | mapping(uint => address) storage _map,
25 | MyStruct storage _myStruct
26 | ) internal {
27 | // do something with storage variables
28 | }
29 |
30 | // You can return memory variables
31 | function g(uint[] memory _arr) public returns (uint[] memory) {
32 | // do something with memory array
33 | }
34 |
35 | function h(uint[] calldata _arr) external {
36 | // do something with calldata array
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/pages/defi/chainlink-price-oracle/Chainlink.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | // import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
5 |
6 | contract ChainlinkPriceOracle {
7 | AggregatorV3Interface internal priceFeed;
8 |
9 | constructor() {
10 | // ETH / USD
11 | priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
12 | }
13 |
14 | function getLatestPrice() public view returns (int) {
15 | (
16 | uint80 roundID,
17 | int price,
18 | uint startedAt,
19 | uint timeStamp,
20 | uint80 answeredInRound
21 | ) = priceFeed.latestRoundData();
22 | // for ETH / USD price is scaled up by 10 ** 8
23 | return price / 1e8;
24 | }
25 | }
26 |
27 | interface AggregatorV3Interface {
28 | function latestRoundData()
29 | external
30 | view
31 | returns (
32 | uint80 roundId,
33 | int answer,
34 | uint startedAt,
35 | uint updatedAt,
36 | uint80 answeredInRound
37 | );
38 | }
39 |
--------------------------------------------------------------------------------
/src/pages/tests/echidna/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Echidna
3 | version: 0.8.10
4 | description: An example of testing contracts with Echidna
5 | ---
6 |
7 | Examples of fuzzing with [Echidna](https://github.com/crytic/echidna).
8 |
9 | 1. Save the solidity contract as `TestEchidna.sol`
10 | 2. In the folder where your contract is stored execute the following command.
11 |
12 | ```shell
13 | docker run -it --rm -v $PWD:/code trailofbits/eth-security-toolbox
14 | ```
15 |
16 | Inside docker, your code will be stored at `/code`
17 |
18 | 3. See the comments below and execute `echidna-test` commands.
19 |
20 | ```solidity
21 | {{{TestEchidna}}}
22 | ```
23 |
24 | ### Testing Time and Sender
25 |
26 | Echidna can fuzz timestamp. Range of timestamp is set in the configuration. Default is 7 days.
27 |
28 | Contract callers can also be set in the configuration. Default accounts are
29 |
30 | - `0x10000`
31 | - `0x20000`
32 | - `0x00a329C0648769a73afAC7F9381e08fb43DBEA70`
33 |
34 | Click [here](https://github.com/crytic/echidna/blob/master/examples/solidity/basic/default.yaml) to see the default configuration
35 |
36 | ```solidity
37 | {{{EchidnaTestTimeAndCaller}}}
38 | ```
39 |
--------------------------------------------------------------------------------
/src/pages/app/write-to-any-slot/Slot.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract Storage {
5 | struct MyStruct {
6 | uint value;
7 | }
8 |
9 | // struct stored at slot 0
10 | MyStruct public s0 = MyStruct(123);
11 | // struct stored at slot 1
12 | MyStruct public s1 = MyStruct(456);
13 | // struct stored at slot 2
14 | MyStruct public s2 = MyStruct(789);
15 |
16 | function _get(uint i) internal pure returns (MyStruct storage s) {
17 | // get struct stored at slot i
18 | assembly {
19 | s.slot := i
20 | }
21 | }
22 |
23 | /*
24 | get(0) returns 123
25 | get(1) returns 456
26 | get(2) returns 789
27 | */
28 | function get(uint i) external view returns (uint) {
29 | // get value inside MyStruct stored at slot i
30 | return _get(i).value;
31 | }
32 |
33 | /*
34 | We can save data to any slot including slot 999 which is normally unaccessble.
35 |
36 | set(999) = 888
37 | */
38 | function set(uint i, uint x) external {
39 | // set value of MyStruct to x and store it at slot i
40 | _get(i).value = x;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/pages/hashing/Keccak256.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | contract HashFunction {
5 | function hash(
6 | string memory _text,
7 | uint _num,
8 | address _addr
9 | ) public pure returns (bytes32) {
10 | return keccak256(abi.encodePacked(_text, _num, _addr));
11 | }
12 |
13 | // Example of hash collision
14 | // Hash collision can occur when you pass more than one dynamic data type
15 | // to abi.encodePacked. In such case, you should use abi.encode instead.
16 | function collision(string memory _text, string memory _anotherText)
17 | public
18 | pure
19 | returns (bytes32)
20 | {
21 | // encodePacked(AAA, BBB) -> AAABBB
22 | // encodePacked(AA, ABBB) -> AAABBB
23 | return keccak256(abi.encodePacked(_text, _anotherText));
24 | }
25 | }
26 |
27 | contract GuessTheMagicWord {
28 | bytes32 public answer =
29 | 0x60298f78cc0b47170ba79c10aa3851d7648bd96f2f8e46a19dbc777c36fb0c00;
30 |
31 | // Magic word is "Solidity"
32 | function guess(string memory _word) public view returns (bool) {
33 | return keccak256(abi.encodePacked(_word)) == answer;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/pages/hacks/block-timestamp-manipulation/BlockTimestamp.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.10;
3 |
4 | /*
5 | Roulette is a game where you can win all of the Ether in the contract
6 | if you can submit a transaction at a specific timing.
7 | A player needs to send 10 Ether and wins if the block.timestamp % 15 == 0.
8 | */
9 |
10 | /*
11 | 1. Deploy Roulette with 10 Ether
12 | 2. Eve runs a powerful miner that can manipulate the block timestamp.
13 | 3. Eve sets the block.timestamp to a number in the future that is divisible by
14 | 15 and finds the target block hash.
15 | 4. Eve's block is successfully included into the chain, Eve wins the
16 | Roulette game.
17 | */
18 |
19 | contract Roulette {
20 | uint public pastBlockTime;
21 |
22 | constructor() payable {}
23 |
24 | function spin() external payable {
25 | require(msg.value == 10 ether); // must send 10 ether to play
26 | require(block.timestamp != pastBlockTime); // only 1 transaction per block
27 |
28 | pastBlockTime = block.timestamp;
29 |
30 | if (block.timestamp % 15 == 0) {
31 | (bool sent, ) = msg.sender.call{value: address(this).balance}("");
32 | require(sent, "Failed to send Ether");
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/pages/constants/index.html.ts:
--------------------------------------------------------------------------------
1 | // metadata
2 | export const version = "0.8.10"
3 | export const title = "Constants"
4 | export const description = "Constant variables"
5 |
6 | const html = `
Constants are variables that cannot be modified.
7 |
Their value is hard coded and using constants can save gas cost.