Deploy a smart contract to Ethereum using Truffle - A step-by-step guide.

  Рет қаралды 31,877

Block Explorer

Block Explorer

2 жыл бұрын

Learn how to test & deploy a smart contract to Ethereum using Truffle.
In this step-by-step guide we create a new production-level smart contract project from scratch, using the Truffle Suite to test and deploy our code. Learn how to write unit tests in a Truffle project, deploy your contract to a local blockchain instance using Ganache and finally deploy your smart contract to Ethereum testnets and mainnet.
Vending machine smart contract code here:
github.com/jspruance/block-ex...

Пікірлер: 100
@jims7089
@jims7089 Жыл бұрын
Watching you make errors, seeing the error messages they produce and watching how you fix them is a great way of learning. Please keep them in!
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Really glad to hear that...thanks for the feedback, and will do!
@achelias8477
@achelias8477 Жыл бұрын
love your honesty and it really shows how programming looks behind the scenes. Its nothing like the fast youtube videos where everything is pink. I loved your video and explanation. Helped better than many others that i watched.
@makklawrence2243
@makklawrence2243 Жыл бұрын
You are perfect for this, calm clear and good at spotting any mistakes. Please do not change that. Each time you run into a hurdles and then find the issue. This is real world.
@pillpollen3154
@pillpollen3154 9 ай бұрын
Huge thanks! Great video!
@sangnguyen6631
@sangnguyen6631 10 ай бұрын
best tutorial so far, thank u so much :D
@mahimamanik3996
@mahimamanik3996 2 жыл бұрын
Thanks for great series! Learning a lot, following along. Keep making awesome videos!
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
Thanks Mahima! Really glad to hear that : )
@ehsanghasaei7474
@ehsanghasaei7474 2 жыл бұрын
Literally this is the best tutorial about Truffle. You made my day! Thanks💌
@nishwithdilani
@nishwithdilani 2 жыл бұрын
Thank you for the simple yet very valuble lesson on blockchain development. I had a difficulty with installing truffle on windows 10. But after installing Python 2.7 and setting Node's phyton config value to phyton2.7 it worked.
@raychidazz
@raychidazz 2 жыл бұрын
👏👏👏👏👏👏 Excellent tutorial, thank you so much for this. Appreciate you man👍
@noahcurry4510
@noahcurry4510 Жыл бұрын
You're A Class man!! Keep it up, thank you
@hypersudo8092
@hypersudo8092 2 жыл бұрын
I like the way you teach in your tutorial I feel relaxed to watch and I watch many hours. Just one request please use react js with truffle so we can learn more. Thank you for your efforts.
@techarch6551
@techarch6551 Жыл бұрын
very nice explanation . Got to know how to work with truffle and test network
@ericksodmg
@ericksodmg 2 жыл бұрын
Brooo I've spent hours trying to find a beginner friendly tutorial on solidity/smart contracts. Everything on Udemy and KZbin is outdated and I can't make it past downloading the right packages. Thank you soooo much! Instant sub.
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
Glad to help out brotha! Thanks for the sub.
@matteodeprezzo5638
@matteodeprezzo5638 2 жыл бұрын
Nice job man! I have recently started working with eth and solidity. And I was going crazy figuring out how to deploy my smart contract to the mainnet. Now thanks to you I think I understand something more
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
Thanks Matteo! I feel your pain brother - i think it took me 3 days to deploy my first contract to mainnet successfully lol.
@yoganandaiyadurai
@yoganandaiyadurai 12 сағат бұрын
Nice tutorial. The command to init truffle is npx truffle init. truffle init will throw up errors. IF migrations.sol is not created then use npx truffle unbox command to create.
@abrahamwilliam6232
@abrahamwilliam6232 2 жыл бұрын
I have been on the web for 3 days trying to figure out how to do this configuration just because it my first time I'm having to deploy using truffle. Thanks so much.
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
It took me 3 days too the first time I deployed to mainnet : ) Glad it was helpful!
@insanedivxxx
@insanedivxxx 2 жыл бұрын
Great video thank you!
@Akhbash
@Akhbash Жыл бұрын
At 21:14 you should be using beforeEach so that tests can be executed in any arbitrary order, by isolating one from another. This way you would correctly assert 99 instead of 199, since the last number is due to the second test, which displays the lack of test isolation and requiring the 3rd test to be executed after the 2nd.
@chidiebereezeokwelume
@chidiebereezeokwelume Жыл бұрын
Your video was really really helpful. I had to come back to write this appreciation comment ❤ Thank you so much for this content and knowledge you shared. All of these for free. I definitely learnt so much 👍 I was struggling with truffle but it's much better now. Thank you ❤
@fupeng2008
@fupeng2008 Жыл бұрын
Thanks a lot! it is helpful!
@Udhoi
@Udhoi 2 жыл бұрын
Thank you! Subbed :*
@code0007able
@code0007able 2 жыл бұрын
very good step by step session and very helpful. Can you show if i have my smart contract inside a spring boot app and i need to deploy in GCP the app . How to do it
@sillystuff6247
@sillystuff6247 Жыл бұрын
Truffle is not just a tool to deploy contracts, it also a _framework_ . And it imposes contract lifecycle management (called _migrations_ ) onto anyone using it. I didn't realize this until I was trying to figure out why I was paying higher than expected Gas fees for deploying contracts. There are _many, many_ tools for deploying EVM smart contracts. Shop around to find one that's simpler, cheaper, and easy to understand.
@wahasify
@wahasify 2 жыл бұрын
Great Tutorial man! really helped a lot, I have a question, can we run our smart contracts on test networks for production if we are using Blockchain as a backend in dapp or we need to deploy it on mainnet.
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Would strongly recommend mainnet only for prod. Test nets can be deprecated at any time, such as post 2.0 merge and have a lot of other shortcomings. Also most token addresses, other smart contract addresses would be different.
@syedmuhammaddanish8511
@syedmuhammaddanish8511 2 жыл бұрын
Bro You are amazing. You are the best. You make best videos.
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
Thanks Syed...I appreciate that my brotha!
@moustafaezz9158
@moustafaezz9158 2 жыл бұрын
Thanks bro
@xx1slimeball
@xx1slimeball 2 жыл бұрын
cool vid! ✅
@waitwhat6797
@waitwhat6797 8 ай бұрын
Anyone else starting to have problems at the client side app part? I don't see anything printed in the browser console, something fails with the app,js file even though I don't get any error message
@petermarsh2174
@petermarsh2174 7 күн бұрын
Hi Jonathan have you done a tutoirial on how to setup VS Code for a development scenario ie exactly how you set your machine.. Thanks in advance
@azertqwert2613
@azertqwert2613 Жыл бұрын
Great tutorial. And I have a question : if we want to deploy another contract, do we have to migrate all the previous contracts and pay gas fees for them or just pay for the new one.
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
You don't have to do anything with the previous contract(s) - just pay for the new one and update any related code with the new address.
@ankushraj3599
@ankushraj3599 Жыл бұрын
Great
@rogerwmwong
@rogerwmwong 10 күн бұрын
Refer to 14:22, I got this warning message, "This version of µWS is not compatible with your Node.js build: Error: Cannot find module '../binaries/uws_linux_x64_127.node'...Falling back to a NodeJS implementation; performance may be degraded.", yet the test is run successfully. Any idea how to fix that warning?
@DevX_0o0
@DevX_0o0 Жыл бұрын
Why do we still want truffle? If we can use only web3 to deploy and interact with contract.
@ahmedsaid50
@ahmedsaid50 Жыл бұрын
Thank you for a great tutorial. Would it be possible to make a full Aave Flashloan arbitrage tutorial on the Ethereum and Binance network using different DEX like Uniswap, Sushiswap and Pancakeswap?or Flashswap? I'm really having some issues with the arbitrage portion of the code.
@NoobDadGaming
@NoobDadGaming 2 жыл бұрын
It looks like the balance is saved between tests, doesn't that defeat the purpose of the Before? Ahh answered my own question... According to MochaJS's documentation on hooks: before (function () {}) runs before all tests in the block. beforeEach (function () {}) runs before each test in the block. For future testing, I would recommend you use beforeEach thus making each test independent, otherwise, if the tests are executed out of order, they will fail. Great job, though! Very helpful!!!!
@srikanthbrendon3243
@srikanthbrendon3243 Жыл бұрын
Hello can you please tell blockchain developer roadmap for freshers
@MohsenJamaligp
@MohsenJamaligp 2 жыл бұрын
Great stuff but when I try to get ether from faucet it throws an error that there is not sufficient gas * value ... any idea?
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
It seems like the RInkeby faucet has been down for some time now. You may have to search around for a 'Ropsten faucet' or 'Kovan faucet' (update your config file to point to whichever network you choose). if all else fails, the Chainlink LINK faucet will give you some Eth: faucets.chain.link/
@MohsenJamaligp
@MohsenJamaligp 2 жыл бұрын
@@BlockExplorerMedia Thank you so much for quick reply :D It worked (kovan network from the link that you sent)
@vashitvaraj3520
@vashitvaraj3520 Жыл бұрын
Hii sir, you are really doing an amazing work. Cheers to your hard work. I just want to know that what version of Truffle you are using in this tutorial. Please let me know asap.
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Thanks! "@truffle/hdwallet-provider": "^2.0.1",
@drakegao816
@drakegao816 Жыл бұрын
Do you know what the gas: property is doing here? I can put any amount there as long as it is not over the limit?
@jatin3709
@jatin3709 Жыл бұрын
Hi Drake, were you able to run truffle test?? I am getting error can you please help
@drakegao816
@drakegao816 Жыл бұрын
Yes, I can run the truffle test by using the default local network with the ganache running
@jatin3709
@jatin3709 Жыл бұрын
Thanks for replying mate, I made a spelling mistake 🤦
@drakegao816
@drakegao816 Жыл бұрын
@@jatin3709 prefer truffle than hardhat so far, I also pushed to Sepolia testnet too. Pretty easy.
@sukiratwarring6219
@sukiratwarring6219 2 жыл бұрын
hi sir can you pls guide me with understanding the test that you write in js...what should i refer to...Just for the info I don't know much js!!
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
hi Sukirat. I am thinking about doing a JS tutorial video for blockchain developers who are new to JS. Until then check out this: kzbin.info/www/bejne/npWsY5WnhM-sacU
@sukiratwarring6219
@sukiratwarring6219 2 жыл бұрын
@@BlockExplorerMedia thanks for replying and looking forward to the course
@anthibn9477
@anthibn9477 2 жыл бұрын
can you upload the vending machine test JS file to your github? im getting errors when trying to run tests
@nassaubahamas8570
@nassaubahamas8570 Жыл бұрын
did you get that solved because i got errors too
@anthibn9477
@anthibn9477 Жыл бұрын
@@nassaubahamas8570 no
@rezaheydari1725
@rezaheydari1725 Жыл бұрын
Hello, thank you very much for this tutorial. But I have a very important question, why the migrations.sol file is not created for me in the project!?
@milanis7a
@milanis7a Жыл бұрын
Is deploying on eth2 with infura different? Because infura menu is now different and I get error while deploying
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
As far as I know it should be the same process but I haven't targeted eth2 myself yet. Guess it is going away in a few days(?)
@milanis7a
@milanis7a Жыл бұрын
@@BlockExplorerMedia Thank you for your great channel and the quick answer, my problem is that when I create new project if I select ETH2 I don't find Rinkeby (only Eth2 and Prater), If I select Web3 API I find Rinkeby but I have an error during deployment (ETIMEDOUT).. I tried to set networkCheckTimeout: 1000000 but it doesn't work.. I think is some kind of problem with infura
@milanis7a
@milanis7a Жыл бұрын
I read more about the merge, I think that Rinkeby and Ropstein are now deprecated, probably only goerli works now
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
hey Stefano, thanks for sharing this. I've been reading up on this too. here are the takaways I found: "Rinkeby, a geth-based proof-of-authority testnet, will not transition to proof-of-stake and will be shut down in Q2/Q3 2023. Users and developers are encouraged to migrate ASAP to Goerli or Sepolia to test Ethereum in a post-merge context." So I'll start using Goerli or Sepolia on future work. Thanks again!
@milanis7a
@milanis7a Жыл бұрын
@@BlockExplorerMedia thank you for your amazing KZbin channel 😍
@frazakhtar8651
@frazakhtar8651 Жыл бұрын
This version of µWS is not compatible with your Node.js build: Error: node-loader: Error: The specified module could not be found. C:\Users\Fraz\AppData\Roaming pm ode_modules\truffle ode_modules\ganache\dist ode/1RGFZdPM.node Falling back to a NodeJS implementation; performance may be degraded. got this error while deploying can anyone help me
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Hi. Which version of Node do you have installed? Make sure you have a compatible Node version - here are the install details: trufflesuite.com/docs/truffle/getting-started/installation/
@lovestudykid
@lovestudykid Жыл бұрын
New version of truffle does not init with migration files
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Looks like they have made some changes. Now 'truffle init' creates an empty project with no example contracts and thus no migration files. If you want those you now have to run 'truffle unbox metacoin' or similar to target one of many starter templates (ie 'truffle unbox {BOX_NAME}'). Or you could explore Hardhat which I've been using more lately. There's a complete example of project setup and deployment in the recent ERC20 video: kzbin.info/www/bejne/nZSalmxmgq2popo
@pankajjoshi8292
@pankajjoshi8292 Жыл бұрын
Can u pls show us to read and write to these contracts using react js frontemd
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Please see any of my 'Web3' tutorials - I have some using web3js and 1 (faucet UI) that uses Ethersjs. Cheers!
@nassaubahamas8570
@nassaubahamas8570 Жыл бұрын
my create new project on infura is different and ethereum is replaced with web3
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Unfortunately the UIs change pretty frequently....a moving target for sure.
@frozenzaid9863
@frozenzaid9863 Жыл бұрын
why did you use 2 private keys, not 1 ? which is the first acc
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
I don't remember the exact reason why I used 2 in this video as it's been a while, maybe just to demonstrate the option. An array of 1 key should work as well.
@drakegao816
@drakegao816 2 жыл бұрын
Why do we need two private keys from the metamask?
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
I don't remember why I used 2 in this video - an array of 1 should work fine.
@drakegao816
@drakegao816 Жыл бұрын
@@BlockExplorerMedia Thanks. Do you think truffle is still good? I am using truffle and familiar with it, however, saw many people start using hardhat now.
@mrxfin
@mrxfin 2 жыл бұрын
What happened when same contract deploy two or three times with same code and same information?
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
Great question. Each new deployment results in a new smart contract on the blockchain with a new address. It is completely unrelated to any previous deployment, even if it has the same name and code.
@mrxfin
@mrxfin 2 жыл бұрын
@@BlockExplorerMedia means every time new smart contract address generated? Even using same code and same information and same Metamask address for deploy?
@BlockExplorerMedia
@BlockExplorerMedia 2 жыл бұрын
That's correct. There's no concept of deploying to the same address or editing an already deployed contract. Each time you end up with a new one with a new address.
@mrxfin
@mrxfin 2 жыл бұрын
@@BlockExplorerMedia thank you for reply.
@prosessorkpt1052
@prosessorkpt1052 Жыл бұрын
How to Deployed smartcontract on DogeChain?
@BlockExplorerMedia
@BlockExplorerMedia Жыл бұрын
Not sure, I haven't worked with Doge Chain yet. Would be interesting. Maybe I will look into it if time allows!
@santeigo123456
@santeigo123456 2 жыл бұрын
1) Contract: VendingMachine allows donuts to be purchased: ReferenceError: account is not defined I am stuck here XD
@justkaz7104
@justkaz7104 Жыл бұрын
470
@tsunningwah3471
@tsunningwah3471 2 ай бұрын
youasregod
@AbubakrIdreesBhutta
@AbubakrIdreesBhutta Жыл бұрын
noob
@michalbotor
@michalbotor Жыл бұрын
hey @BlockExplorerMedia, thanks for the tutorial! i have found this autocompletion very annoying too, i disabled it by unchecking "Editor: Accept Suggestion On Commit Character" in the settings. hope this helps you if it still bothers you.
@michalbotor
@michalbotor Жыл бұрын
omg. i spent like two hours getting angrier and angrier at truffle because the "truffle test" was returning me the following error "Something went wrong while attempting to connect to the network at host: localhost, port: 7545. Check your network configuration." only to realize by some digging that i am missing.. a blockchain! in order to run truffle one has to run traffle suite: ganache blockchain in the separate process. @BlockExplorerMedia have you by any chance been already running it when you were running your "truffle test" command? after i got it running it turned out that my VendingMachine.test.js file was buggy. one error that i don't understand is the following: in the before function i wrote `const vm = await VendingMachine.deployed()` instead of `vm = await VendingMachine.deployed()` and the `vm` object was not visible in the `it` function. why? are `const/let/var` objects in javascript local and `` objects global, and we have to use global?
@crlsable
@crlsable 2 жыл бұрын
When I tried this: truffle migrate --network rinkeby Get the message below: C:\Projects\truffle-tutorial\vendingmachine ode_modules\eth-block-tracker\src\polling.js:51 const newErr = new Error(`PollingBlockTracker - encountered an error while attempting to update latest block: ${err.stack}`) ^ Error: PollingBlockTracker - encountered an error while attempting to update latest block: undefined at PollingBlockTracker._performSync (C:\Projects\truffle-tutorial\vendingmachine ode_modules\eth-block-tracker\src\polling.js:51:24) at processTicksAndRejections (internal/process/task_queues.js:95:5) at runNextTicks (internal/process/task_queues.js:64:3) at listOnTimeout (internal/timers.js:526:9) at processTimers (internal/timers.js:500:7) UnhandledRejections detected Promise { { code: -32603, message: 'ETIMEDOUT', data: { originalError: [Object] } } } { code: -32603, message: 'ETIMEDOUT', data: { originalError: { code: 'ETIMEDOUT', connect: true } } } Promise { { code: -32603, message: 'ETIMEDOUT', data: { originalError: [Object] } } } { code: -32603, message: 'ETIMEDOUT', data: { originalError: { code: 'ETIMEDOUT', connect: true } } }
@crlsable
@crlsable 2 жыл бұрын
rinkeby: { provider: () => new HDWalletProvider({ privateKeys: private_keys, providerOrUrl:'**********proposital****', numberOfAddress: 2 } ), network_id: 4, gas: 5500000, confirmations: 2, timeoutBlocks: 200, skipDryRun: true },
@wahasify
@wahasify 2 жыл бұрын
Change your network_id to 4, got the same error. it will work..
Learn Solidity: The COMPLETE Beginner’s Guide (Latest Version 0.8)
1:39:11
Smart Contract Tutorial - Create a lottery smart contract in Solidity
45:23
Зу-зу Күлпәш.Курс (6 бөлім)
40:48
ASTANATV Movie
Рет қаралды 542 М.
The World's Fastest Cleaners
00:35
MrBeast
Рет қаралды 145 МЛН
How did CatNap end up in Luca cartoon?🙀
00:16
LOL
Рет қаралды 7 МЛН
ISSEI funny story😂😂😂Strange World | Pink with inoCat
00:36
ISSEI / いっせい
Рет қаралды 29 МЛН
Flash Loan Arbitrage | Aave Flash Loan Tutorial
48:34
Block Explorer
Рет қаралды 127 М.
Web3 Tutorial Project | Build a web3js dApp for a smart contract
1:52:33
Block Explorer
Рет қаралды 107 М.
How to Become a Blockchain Developer
25:33
Block Explorer
Рет қаралды 52 М.
ERC20 Token Tutorial | Create Your Own Cryptocurrency
1:13:56
Block Explorer
Рет қаралды 123 М.
Smart Contract Tutorial - Vending Machine Smart Contract in Solidity
34:34
They Enabled Postgres Partitioning and their Backend fell apart
31:52
Hussein Nasser
Рет қаралды 36 М.
Ganache and Metamask | Blockchain
19:52
ADCB innovations
Рет қаралды 6 М.
Вы поможете украсть ваш iPhone
0:56
Romancev768
Рет қаралды 609 М.
Samsung vs Apple Vision Pro🤯
0:31
FilmBytes
Рет қаралды 310 М.
Any Sound & Call Recording Option Amazing Keypad Mobile 📱
0:48
Tech Official
Рет қаралды 325 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 3,9 МЛН