Skip to content

Commit

Permalink
Merge branch 'master' into jacob/docs-chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-moore-cb authored Feb 9, 2024
2 parents 2a01dbc + 7a157a8 commit 3d1d788
Show file tree
Hide file tree
Showing 108 changed files with 4,291 additions and 425 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ This project and everyone participating in it are governed by our [Code of Condu

### Reporting Bugs

1. **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/base-org/web/issues).
1. **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/web/web/issues).

2. If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/base-org/web/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.

### Suggesting Enhancements

1. **Check the [Issues](https://github.com/base-org/base/issues)** to see if there's someone who has already suggested the same enhancement.
1. **Check the [Issues](https://github.com/base-org/web/issues)** to see if there's someone who has already suggested the same enhancement.

2. If it doesn't exist, [create a new issue](https://github.com/base-org/base/issues/new). Provide a clear and detailed explanation of the feature you want and why it's important to add.
2. If it doesn't exist, [create a new issue](https://github.com/base-org/web/issues/new). Provide a clear and detailed explanation of the feature you want and why it's important to add.

### Pull Requests

Expand All @@ -53,4 +53,4 @@ This project and everyone participating in it are governed by our [Code of Condu

---

Feel free to customize this template according to the specific needs and nuances of Base Web. A well-crafted `CONTRIBUTING.md` can help your project attract quality contributions and foster a collaborative community.
Feel free to customize this template according to the specific needs and nuances of Base Web. A well-crafted `CONTRIBUTING.md` can help your project attract quality contributions and foster a collaborative community.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: Address and Payable in Solidity
description: A comprehensive guide to understanding and using address and payable address types in Solidity.
hide_table_of_contents: false
---

Understanding address and payable address types is crucial for managing Ether transfers and interactions within your Solidity contracts. This article will delve into their key distinctions and practical applications.

---

## Objectives

By the end of this lesson, you should be able to:

- Differentiate between address and address payable types in Solidity
- Determine when to use each type appropriately in contract development
- Employ address payable to send Ether and interact with payable functions

---

## Ethereum Addresses

In Solidity, Ethereum addresses play a crucial role in interacting with the Ethereum blockchain. An Ethereum address is a 20-byte hexadecimal string that represents the destination of transactions or the owner of a smart contract. These addresses are used to send and receive Ether and interact with smart contracts.

### Addresses

Regular addresses in Solidity are used for various purposes, including:

- Identifying the owner of a smart contract
- Sending Ether from one address to another
- Checking the balance of an address
Here's an example of declaring a regular address variable in Solidity:

<br />

```solidity
address public owner;
```

### Payable Addresses

`payable` keyword is a language-level feature provided by Solidity to enable the handling of Ether within smart contracts, and it is not a feature of the Ethereum Virtual Machine itself, but rather a part of the Solidity language's syntax. They are used when you want a contract to be able to receive Ether from external sources, such as other contracts or user accounts.

Payable addresses are often used when creating crowdfunding or token sale contracts, where users send Ether to the contract's address in exchange for tokens or to fund a project.

Here's an example of declaring a payable address variable in Solidity:

```solidity
address payable public projectWallet;
```

Payable [Address] are marked as payable, which means they can accept incoming Ether transactions. It's important to note that regular addresses cannot receive Ether directly.

## Receiving Ether with Payable Addresses

To receive Ether in a contract using a payable address, you need to define a payable function that can accept incoming transactions. This function is typically named receive or fallback. Here's an example:

```solidity
fallback() external payable {
// Handle the incoming Ether here
}
```

In this example, the fallback function is marked as external and payable, which means it can receive Ether when someone sends it to the contract's address. You can then add custom logic to handle the received Ether, such as updating contract balances or triggering specific actions.

## Usage

```solidity
contract PaymentReceiver {
address payable owner;
constructor() payable {
owner = payable(msg.sender); // Convert msg.sender to payable
}
function receiveEther() public payable {
// This function can receive Ether
}
function withdrawEther() public {
owner.transfer(address(this).balance); // Send Ether to owner
}
}
```

## Conclusion

Appropriately using address and address payable types is essential for secure and efficient Solidity contract development. By understanding their distinctions and applying them correctly, you can effectively manage Ether transfers and interactions within your contracts.

[Address]: https://docs.soliditylang.org/en/latest/types.html#address
4 changes: 1 addition & 3 deletions apps/base-docs/base-camp/docs/arrays/arrays-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ Add `public` functions called `resetSenders` and `resetTimestamps` that reset th

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Create a function called `doNotDisturb` that accepts a `uint` called `_time`, an

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Stay tuned for updates!

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ As the popularity and possibilities of building onchain have increased, so has t

However, the setup of professional tools for local development is far less burdensome than it used to be. [Foundry] and [Hardhat] are two popular choices, both with excellent communities.

You may wish to select and install one of these now, but feel free to skip those sections and go to right [Smart Contract Development] if your happy learning with an online editor!
You may wish to select and install one of these now, but feel free to skip those sections and go to right [Smart Contract Development] if you're happy learning with an online editor!

[Remix]: https://remix.ethereum.org/
[Foundry]: https://book.getfoundry.sh/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ If this vote takes the total number of votes to or above the `quorum` for that v

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ The contract specification contains actions that can only be performed once by a

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ contract ErrorTriageExercise {

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
16 changes: 13 additions & 3 deletions apps/base-docs/base-camp/docs/imports/imports-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ Remember, the compiler will automatically create a getter for `public` `struct`s

## Submit your Contract and Earn an NFT Badge! (BETA)

:::caution

#### Contract Verification Best Practices

To simplify the verification of your contract on a blockchain explorer like BaseScan.org, consider these two common strategies:

1. **Flattening**: This method involves combining your main contract and all of its imported dependencies into a single file. This makes it easier for explorers to verify the code since they only have to process one file.

2. **Modular Deployment**: Alternatively, you can deploy each imported contract separately and then reference them in your main contract via their deployed addresses. This approach maintains the modularity and readability of your code. Each contract is deployed and verified independently, which can facilitate easier updates and reusability.

:::

:::info

#### Hey, where'd my NFT go!?

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ contract InheritanceSubmission {

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
4 changes: 1 addition & 3 deletions apps/base-docs/base-camp/docs/mappings/mappings-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ Add a function called `resetUserFavorites` that resets `userFavorites` for the s

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ A failure of either of these checks should result in a revert with an `UnsafeTra

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ The `AddressBookFactory` contains one function, `deploy`. It creates an instance

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
4 changes: 1 addition & 3 deletions apps/base-docs/base-camp/docs/storage/storage-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ function debugResetShares() public {

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
4 changes: 1 addition & 3 deletions apps/base-docs/base-camp/docs/structs/structs-exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ Add a public function called `resetMyGarage`. It should delete the entry in `gar

[Testnets](../deployment-to-testnet/test-networks) are not permanent! Base Goerli [will soon be sunset](https://base.mirror.xyz/kkz1-KFdUwl0n23PdyBRtnFewvO48_m-fZNzPMJehM4), in favor of Base Sepolia.

We recommend changing the network to **Base Sepolia**, and submitting your contracts there. While it is still supported, you can change the network to Base Goerli to see your existing NFT.

However, as these are separate networks with separate data, your NFTs **will not** transfer over.
As these are separate networks with separate data, your NFTs **will not** transfer over.

**Don't worry!** We've captured the addresses of all NFT owners on Base Goerli and will include them when we release the mechanism to transfer these NFTs to mainnet later this year! You can also redeploy on Sepolia and resubmit if you'd like!

Expand Down
11 changes: 11 additions & 0 deletions apps/base-docs/base-camp/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,17 @@ const sidebars = {
},
],
},
{
type: 'category',
label: 'Address and Payable',
items: [
{
type: 'doc',
id: 'docs/address-and-payable/address-and-payable',
className: 'sidebar-coding',
},
],
},
],
},
{
Expand Down
Loading

0 comments on commit 3d1d788

Please sign in to comment.