Introduction to Introduction to Smart Contracts with Ethereum and Solidity
lessonDuration 2m 9sFree
Welcome to Noah's course on Introduction to Smart Contracts with Ethereum and Solidity.
Browse
Find courses, lessons, articles, talks, and podcasts.
16 results for "solidity"
lessonDuration 2m 9sFree
Welcome to Noah's course on Introduction to Smart Contracts with Ethereum and Solidity.
lessonDuration 5m 28s
Now that Foundry is installed, we can build out the functionality of our smart contract written in Solidity. We'll create various functions that allow you to increment, decrement, and read a number whose state is kept in your smart contract. All of the functions will have different visibility modifiers and types that constrain the behavior of your functions. We'll create our own custom error that is thrown whenever you step outside the bounds of your intended functionality.
course
Smart Contracts are programs stored on the blockchain that run when certain conditions are fulfilled. These Smart Contracts have many benefits to them such as speed, transparency, and security. The contract is immediately run as soon as the requirements are fulfilled. This creates a system where you place trust in a transparent system, instead of an opaque intermediary. Noah will show you how to write, test, and deploy smart contracts on Ethereum, using the popular smart contract language, Solidity. You'll also learn how to use Foundry, a popular dev-toolbelt, to streamline our whole development process. Throughout this course, you'll learn how to: - safely and securely set up Smart Contracts - write and read data on your Smart Contract - send transactions with specific arguments to your Smart Contract - deploy your Smart Contract using Forge and QuickNode And more!
lessonDuration 8m 12s
To reduce the amount of gas used, we will create a withdraw function that lets the owner of the contract withdraw funds that have been added when they want rather than withdraw with every transaction. Your smart contract is ready to be used, since you have confidence in the code after testing it. But there are a few things that you can add to improve the behavior and security of it. Let's start by adding events. Similar to any other programming language Events in solidity are a way to inform the calling application about the current state of the contract. Like notifying the javascript client about a change made to the contract allowing the client application to react to it. Events are defined within the contract as a global and are called from inside a function. To declare an event you use the `event` keyword, followed by an identifier and the parameter list. The values passed to the parameters are then used to log the information that is saved as part of the transaction inside the block. To send the event you'll use the `emit` keyword from anywhere inside the contract by passing the name of the event and the corresponding parameters. For this contract you want to let the client application to know when a tip was successfully sent. To do that you'll create a new event named `NewTip` like this ```javascript event NewTip(address indexed from, string message, string name, uint256 amount); ``` It will accept an address to identify who sent the tip, the message of the tip and also the name and the amount of eth sent, And then, it will be emitted from the `sendTip` function ```javascript // send the event emit NewTip(msg.sender, _message, _name, msg.value); ``` This event will use the same parameters that the rest of the `sendTip` operation. - `msg.sender` to get the address of who sent the tip - `_message` the string with the message sent - `_name` the name of the sender - `msg.value` the amount of `eth` sent.
lessonDuration 5m 33s
The first step in this journey will be get your hands into a new language to harness the power of the blockchain. I'm talking about Solidity **This isn't a Solidity focused course but we will review some concepts to get you up to speed with it. The first thing to notice is that Solidity is an statically-typed language created specifically to create smart contracts for the Ethereum network. An smart contract is like "real life" contract. Is a way to establish terms for an agreement. But the "smart" part it's because this type of contract is declared as machine code that is executed in a blockchain. This expand the idea of the original blockchain, Bitcon, aout sending and receiveing money without a centralized intermiediary to create trust and make possible to automate and dcentralize virtually any kinf of deal or transaction. Since the contracts run in the blockchain (like Ethereum network) they offer high security, trust, inmmutability and reliability. Since the blockchain is immutable you have to be care on what are you deploying. After deployed it cannot be change and you'll need to deploy a new contract. For Solidity, a contract is a collection of code (a program) and data (the state) that lives inside the blockchain, it can be identify by its Ethereum address. You can leverage your previous knowledge and use some analogies to understand the smart contract. You can think on the contract as your "backend" or "server side" program. This server expose an API and store some data (the state) into the a databse (the blockchain), but the database is not written nor query with a different language like SQL, you can imagine that Solidity is automatically connected to the database and everything you deeclare (like a variable) is stored in the database.
lessonDuration 4m 54s
Now is time to setup the client to talk with the contract, for that you will need to store and access the contract ABI (this is a file generated by the contract compilation) as well as use ethers to set up a connection to the contract. Once set up is complete, we will listen to any tip events that come in from the contract and display tip information in the application. ## Important SvelteKit is still in beta. Expect bugs! Read more here, and track progress towards 1.0 here. This lesson was recorded before the latest breaking changes, the content is still valid but it sometimes references a file that does not exists anymore. Now: `src/routes/index.svelte` is called `src/routes/+page.svelte` `src/routes/__layout.svelte` is called `src/routes/+layout.svelte` Everything else is 100% valid. This particular content will be updated when Sveltekit reaches 1.0.0 stable.
lessonDuration 2m 56s
It is time to interact with the contract, let's send some eth! For this you'll need a form that is rendered only when the wallet is connected. This form use the `sendTip` function and gather some required information. On submit, it will read the `sendingTip` loading state variable and disable or enable the button. ## Important SvelteKit is still in beta. Expect bugs! Read more here, and track progress towards 1.0 here. This lesson was recorded before the latest breaking changes, the content is still valid but it sometimes references a file that does not exists anymore. Now: `src/routes/index.svelte` is called `src/routes/+page.svelte` `src/routes/__layout.svelte` is called `src/routes/+layout.svelte` Everything else is 100% valid. This particular content will be updated when Sveltekit reaches 1.0.0 stable.
lessonDuration 3m 5s
We will use the `Test.sol` smart contract that Forge provides to turn your smart contract into something that can be tested. We'll configure the file using the `setup` function and successfully run our test suite.
lessonDuration 4m
Here in the same file, `Contract.t.sol`, we'll test your smart contract's `increment` and `decrement` functions. We will learn about how Forge will fuzz tests and how to properly constrain the `vm` object to ensure you are testing it under the right specific conditions.
lessonDuration 2m 47s
Now you need a way to keep a local network alive, deploy the smart contract there and then interact with it. You can think on this like a local web server. When you develop an API you have a local server running it so the client application can talk to it so you can develop and test, this is the same idea. Head over to your terminal and run tthe following command. ```bash $ npm run hardhat node ``` This will ramp up a local ethreum network using hardhat and will show in the console a set of accounts and private keys that can be used for testing pruposes. These are 20 test accounts and addresses created for your. Each account is also rich! are loaded with 10000 ETH. (fake eth btw). Right now this is just an empty blockchain. There are no blocks nor smart contracts on it. But you want to create a new block and put the smart contract that you just created there, for that you need to create a little script that will use ethers.js power to compile and deploy.
course
Web3 is a paradigm shift in how applications are interacted with, ran, and built. It’s not just a Pump-and-Dump scheme on cryptocurrencies or Bored Ape NFT profile pictures you can put on Twitter. A fundamental tenet of Web3 is bringing ownership back to the user. You no longer have to trust that your data is being properly handled on someone else’s server (although, currently Web3 ecosystem mainly depends on centralized infrastructure such as GitHub). This ownership is achieved through blockchain, cryptocurrencies, NFTs, and smart contracts. A great example of this type of ownership is through how you exchange money in Web3. There is no intermediary like Stripe, or PayPal to process your transactions. You can even build your own smart contracts that receive crypto (e.g. Ethereum or ‘eth’ for short) and then process that eth how you’d like. Building this type of smart contract is exactly what Matías is going to show you how to do right now. Matías builds out a Web3 application that allows you to receive tips in the form of eth in a tip jar on your website. This means your application will be backed by a smart contract that’s accepts eth, stores data, and emits Solidity events. The frontend application uses SvelteKit which you’ll see how easy it is to get up and be productive with in minutes. A huge benefit here is that the JavaScript you write is just that, JavaScript. You’ll be able to take what you learn and implement it into any framework of your choosing. While you build this application you will learn how to: - Write a smart contract using Solidity language - Test the smart contract using just JavaScript through the waffle framework - Communicate and interact with the smart contract using ethers.js in a SvelteKit application - Deploy your smart contract to make it public and accessible to anyone
lessonDuration 5m 24s
Tests are important, as always but it may be more important when you are developing an smart contract. Why? Because the blockchain is immutable. The main difference between Solidity development and other languages or environment is that after the implementation of an smart contract in the Ethereum network the contract is immutable, meaning that it will never be modified or updated again. The first code that get's deployed is the one that will remains unchanged for the rest of time. This is because one the main concerns of Solidity is security. If there's a flaw in your contract code, there is no way to patch it later. You would have to tell to the users of the contract to use a different contract (identified by an `address`) to get the fix. Sounds uncomfortable right? But, believe it or not, this is a **feature**. The code that your wrote it becomes a **law**. IF you read the code of an smart contract (and verified that that code is actually the one deployed) you can be sure that every time you call a function it will behave exactly as the code says it. So you need to be sure before deploy and the best way to get that confidence is by testing. [Hardhat](https://hardhat.org/) (the development environment of choice for this course) offers the tools to test the smart contract using Javascript or Typescript by leveraging the power of [Ethers.js](https://docs.ethers.io/) to interact with the Ethereum network and [Waffle](https://getwaffle.io/), a testing library built on top of Ethere.js You already dip your toes on a bit of testing code, now let's add a more robust test to check that the contract behaves as expected.
lessonDuration 4m 10s
Now that we tested a smart contract in solidity with fuzzed inputs, we'll move on to testing our smart contracts in an idiomatic fashion. We will delete the negative test case for the `decrement` function, and will replace it with a function that expects a specific error instead of any generic failure. The `vm` object is used to do this, and we'll pick up on the vocabulary word "cheatcode" which is a reference to the various utilities that forge provides you through the `vm` object. [Here are more examples](https://book.getfoundry.sh/forge/cheatcodes.html) of how cheatcodes are used. And [here is the reference sheet](https://book.getfoundry.sh/cheatcodes/) for an overview of all the available cheatcodes.
lessonDuration 2m 12sFree
There is a lot of hype around Web 3 this past year. We are all learning as a community what it can do and the ways you can utilize decentralized applications as a developer. This course is your guide to getting started with Web 3. One of the key concepts in Web 3 to learn about is the Smart Contract. This course will teach you what it is and how to write one. You'll learn how to: - Write a smart contract using Solidity language - Test the smart contract using just JavaScript through the waffle framework - Communicate and interact with the smart contract using ethers.js in a SvelteKit application - Deploy your smart contract to make it public and accessible to anyone I hope you enjoy!
lessonDuration 2m 49s
It's time to add functionality to our smart contract. In this lesson we will define a function `sendTip` that accepts a `_message` and `_name`. We will check the senders balance and if it's higher than the tip amount transer the eth specified. We will also increment our `totalTips` contract variable and add the tip to our Tips array. While adding this function you'll learn how to handle errors within Solidity functions
lessonDuration 2m 19s
We want to actually sell our NFT tickets, so let’s set a mint price. In our smart contract, we can just set the price to an integer variable. We’ll then make our mint function `payable`. When a function is payable in Solidity it means it can receive ether. Once our mint function is payable, we can call the `require` function to check if the initiator of the function is sending enough ether.