Smart Contracts 101 - Simple Ether Wallet Smart Contract Tutorial
Вставка
- Опубліковано 30 січ 2022
- In this Solidity Ethereum smart contract tutorial we build simple Ether wallet smart contract to review the basics of sending and receiving funds to and from a smart contract.
Remix IDE:
remix.ethereum.org/ - Наука та технологія
I just did this along with you (on my laptop). I was practicing and taking notes as you were explaining everything. I got the same results as you did in this video. I'm trying to learn as much as I can. I want to be proficient in coding smart contracts. Thank you very much for this tutorial! Helpful as always! :)
It's great to hear that you got the same results! So glad it was helpful : )
@yoshika pls I am looking for a study partner
@@codefactory3190, hi! Okay! Actually, I will be starting the DApp University's bootcamp, soon, to gain an understanding of everything pertaining to coding smart contracts, etc...However, it you want to study together, that's not a problem at all. Thank you!
Thank you so much for this. I just got started learning how to code smart contracts in solidity. I have some programming experience but was never really good at it. You explain things in a way I can understand.
Awesome video! Everything was clear, concise and to the point, loved it!
Great job man. Very clearly explained. Much easier to learn by creating something than memorising the syntax one by one. Short as well. I find myself getting stuck halfway when learning to do complicated projects, just to lose motivation and give up.
Superb explanation. Enjoyed the tutorial.
Great quality! Love the detail and speed
Thanks Rikia
hey bud ... I was trying this by myself and made a few silly mistakes. The video helped me get back on track quickly. Thanks.
You are doing great job🔥. Thanks for your one by line explanation.First,. I have lot of misunderstanding about the contract access. But, now I have got an idea very clearly. Thank you so much buddy❤️🔥😎.
hey this was great! looking forward to more
Great video bro!
Man, just keep doing this, please!
Hi Jonathan,
Thank you so much for this tutorial!
I'm going over your entire Blockchain playlist just to understand what you did in the flashloan tutorial. I was watching the vending machine tutorial and the explanation in your first Smart Contract 101. But after watching the lottery tutorial I still had some questions about what you did.
You answered a lot of those questions in this tutorial and I'm very grateful for that. And I hope you can help me with the last few questions I have...
In this video you broke down what's inside the contract function. But to be honest I'm still not sure about what the contact function is and what it does.
Also, you explained a bit about the constructor function, but I'm still not sure about what that is and why and when we should use that.
Finally, you used payable four times in this code. And I'd like to understand better when we should use payable and when not.
Do you think you could create another video which explains these things more clearly? And if you're willing to that, would you also go over the msg.sender one more time, but this time maybe a bit more elaborate?
Thank you in advance, Jonathan! :)
thank you
Why can you use the Auto complier, to avoid compiling the contract each time.
This are great works
Thanks
Great. How do you then let this EtherWallet interact with other smart contracts? eg: deposit funds into aave
Can anyone help me to do my project please...My Project is REPLACING EMAIL PROTOCOL WITH BLOCKCHAIN BASED SMART CONTRACT
Will it only receive eth tokens or all tokens(bsc,matic,etc)?
Thanks for sharing. If I want to do the same by Polygon USDT smart contract, how will I write the code differently? Or could you do a step by step video showing what to do?
Polygon runs on the Ethereum virtual machine (EVM) so the great news is you don't need to make any code changes for that chain. Just target Polygon instead of Ethereum when you deploy. For working with a token other than the native token of the given blockchain, use an ERC20 interface to create a local instance of the token contract. A couple of my videos show how to do that, including the Faucet mart contract and a few others.
Thank you. Do you tutor?
Keep up the great work!
Thanks! Have not done any tutoring yet - I have been super busy with work and side projects. Maybe at some point when things settle down a bit!
Hey, I love your videos! can you please tell me how to hard code a withdrawal address into an nft smart contract?
Thanks Jarifa! Do you mean so that any NFT minted by that contract will go to the hardcoded address? If so, check out line 21 here where it says '_mint(msg.sender, ...)' msg.sender is the recipient of the NFT so you could hardocde this to any address or the contract owner if you want:
github.com/jspruance/erc-721-nft-contract-tutorial/blob/main/contracts/CryptoBeetles.sol
hope that helps
@@BlockExplorerMedia Hey. Thank you so much for your response. I’m working with a developer to launch an nft collection. I want to make sure the revenue from sales is withdrawn to my account and the developer doesn’t scam me by using his wallet address instead. How can I make sure this doesn’t happen? If I check the smart contract he is making and deploy it myself will that help? Is there a way to make sure he doesn’t change the wallet address after the deployment ie hard coding it? I really appreciate your help on this.
ok, got it. so if you have a smart contract that it going to be holding funds which only you should have access to withdraw I would highly recommend doing the deployment yourself and not trusting anyone else to do it for you. the reason being that it is very common in smart contract development for the 'owner' of the contract to be established at the time the contract is deployed. for example, in the constructor:
constructor() {
owner = msg.sender;
}
you want to make sure that 'msg.sender' refers to your wallet address (the one you will be using to transfer funds from smart contract to yourself). 'msg.sender' in the constructor always refers to the wallet address that is deploying the contract. it isn't possible for anyone to change this after deployment, but you do want to make sure this is done right during deployment.
also you'll probably want to implement a withdraw function in the contract that only the 'owner' (you) can access (use an 'onlyOwner' modifier) to control access to this function.
ex:
address public owner;
modifier onlyOwner() {
require(owner == msg.sender, "Only the owner can call this function");
_;
}
function withdraw() external onlyOwner {
payable(owner).transfer(address(this).balance)
}
@@BlockExplorerMedia Thank you so so much! I really appreciate your help on this as I wasn’t sure what to do. Thank you again and all the best with your endeavours.
Anytime...good luck with your project!
Is there a way to make the contract pay for the gas fee to withdraw? (maybe passing some property in .tranfer) ..
There is a concept of 'gas sponsorship' in which a 3rd party contract determines who pays for the gas fees. So you can have your app pay gas on behalf of the user for example. Part of the EIP-4337 spec. See:
medium.com/infinitism/erc-4337-account-abstraction-without-ethereum-protocol-changes-d75c9d94dc4a
Shouldn't getBalance return 125 instead 25 ether since the owner account already had 100 ethers at the start ? Or is it that the contract starts reading the balance from the time it was deployed ?
I might be wrong, but I think that's because the smart contract has its own address which is a unique address and thus different from the address of the owner.
Jonathan, could you comment on this just to make sure I'm right about this?
Why does mine does not have the java script environment it has remix vm
Hey how do you choose which account to credit into? how do I know which address its crediting the amount into, Can I specify which account I want to credit to
In this contract we're using the global 'msg.sender' object which resolves to the active address of the wallet currently interacting with the smart contract. You could change this to any address you want as well. Does that make sense?
@@BlockExplorerMedia From the drop down free address list 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 (debit from) and transfer 25 ether to (0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db).. can you make a small video of hardcoded address and transfer between the two, I somehow managed it, but mine seems less comprehendible
Can anyone tell me how can I change the value from Wei to Ether.
Can we send all ethers in our wallet to a smart contract?
Yes, smart contracts can receive Ether as long as they have a receive or fallback function.
In theory, does this mean that we're able to create our own wallets without having to rely on wallets that are provided by exchanges?
What is the mean of 101 ?
This means it's an intro to the topic - thanks!
slknklfnklnfkl
my solution for this task
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract wallet{
address payable public manager;
constructor(){
manager = payable(msg.sender);
}
receive() payable external {}
function widtdraw(uint x) public {
require(msg.sender == manager, "You do not have permission.");
require(address(this).balance > x, "This contract doesnot have enough ether.");
manager.transfer(x);
}
function Bal() public view returns(uint){
return (address(this).balance);
}
}