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

Поділитися
Вставка
  • Опубліковано 3 січ 2022
  • 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 Рік тому +16

    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  Рік тому +1

      Really glad to hear that...thanks for the feedback, and will do!

  • @achelias8477
    @achelias8477 Рік тому +2

    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.

  • @mahimamanik3996
    @mahimamanik3996 2 роки тому +2

    Thanks for great series! Learning a lot, following along. Keep making awesome videos!

  • @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.

  • @ehsanghasaei7474
    @ehsanghasaei7474 2 роки тому

    Literally this is the best tutorial about Truffle. You made my day! Thanks💌

  • @matteodeprezzo5638
    @matteodeprezzo5638 2 роки тому +4

    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 роки тому +2

      Thanks Matteo! I feel your pain brother - i think it took me 3 days to deploy my first contract to mainnet successfully lol.

  • @hypersudo8092
    @hypersudo8092 2 роки тому +1

    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.

  • @ericksodmg
    @ericksodmg 2 роки тому +2

    Brooo I've spent hours trying to find a beginner friendly tutorial on solidity/smart contracts. Everything on Udemy and UA-cam is outdated and I can't make it past downloading the right packages.
    Thank you soooo much! Instant sub.

  • @raychidazz
    @raychidazz 2 роки тому

    👏👏👏👏👏👏 Excellent tutorial, thank you so much for this. Appreciate you man👍

  • @techarch6551
    @techarch6551 Рік тому

    very nice explanation . Got to know how to work with truffle and test network

  • @sangnguyen6631
    @sangnguyen6631 11 місяців тому

    best tutorial so far, thank u so much :D

  • @noahcurry4510
    @noahcurry4510 Рік тому

    You're A Class man!! Keep it up, thank you

  • @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!

  • @pillpollen3154
    @pillpollen3154 10 місяців тому

    Huge thanks! Great video!

  • @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 ❤

  • @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.

  • @insanedivxxx
    @insanedivxxx 2 роки тому

    Great video thank you!

  • @syedmuhammaddanish8511
    @syedmuhammaddanish8511 2 роки тому

    Bro You are amazing. You are the best. You make best videos.

  • @fupeng2008
    @fupeng2008 Рік тому

    Thanks a lot! it is helpful!

  • @Udhoi
    @Udhoi 2 роки тому

    Thank you! Subbed :*

  • @yoganandaiyadurai
    @yoganandaiyadurai 15 днів тому

    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.

  • @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.

  • @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.

  • @xx1slimeball
    @xx1slimeball 2 роки тому

    cool vid! ✅

  • @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.

  • @petermarsh2174
    @petermarsh2174 22 дні тому

    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

  • @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!!!!

  • @moustafaezz9158
    @moustafaezz9158 2 роки тому

    Thanks bro

  • @rogerwmwong
    @rogerwmwong 25 днів тому

    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?

  • @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.

  • @DevX_0o0
    @DevX_0o0 Рік тому

    Why do we still want truffle? If we can use only web3 to deploy and interact with contract.

  • @waitwhat6797
    @waitwhat6797 9 місяців тому

    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

  • @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.

  • @srikanthbrendon3243
    @srikanthbrendon3243 Рік тому

    Hello can you please tell blockchain developer roadmap for freshers

  • @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 роки тому +1

      hi Sukirat. I am thinking about doing a JS tutorial video for blockchain developers who are new to JS. Until then check out this: ua-cam.com/video/hdI2bqOjy3c/v-deo.html

    • @sukiratwarring6219
      @sukiratwarring6219 2 роки тому

      @@BlockExplorerMedia thanks for replying and looking forward to the course

  • @Moh3enJamali
    @Moh3enJamali 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 роки тому +1

      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/

    • @Moh3enJamali
      @Moh3enJamali 2 роки тому

      @@BlockExplorerMedia Thank you so much for quick reply :D It worked (kovan network from the link that you sent)

  • @ankushraj3599
    @ankushraj3599 Рік тому

    Great

  • @anthibn9477
    @anthibn9477 2 роки тому +1

    can you upload the vending machine test JS file to your github? im getting errors when trying to run tests

  • @lovestudykid
    @lovestudykid Рік тому +3

    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:
      ua-cam.com/video/gc7e90MHvl8/v-deo.html

  • @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 Рік тому +1

      Yes, I can run the truffle test by using the default local network with the ganache running

    • @jatin3709
      @jatin3709 Рік тому +1

      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.

  • @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!

  • @milanis7a
    @milanis7a Рік тому

    Is deploying on eth2 with infura different? Because infura menu is now different and I get error while deploying

    • @BlockExplorerMedia
      @BlockExplorerMedia  Рік тому +1

      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 Рік тому +1

      @@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 Рік тому +1

      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 UA-cam channel 😍

  • @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 роки тому +1

      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 роки тому +3

      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.

  • @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/

  • @nassaubahamas8570
    @nassaubahamas8570 Рік тому

    my create new project on infura is different and ethereum is replaced with web3

    • @BlockExplorerMedia
      @BlockExplorerMedia  Рік тому +1

      Unfortunately the UIs change pretty frequently....a moving target for sure.

  • @santeigo123456
    @santeigo123456 2 роки тому

    1) Contract: VendingMachine
    allows donuts to be purchased:
    ReferenceError: account is not defined
    I am stuck here XD

  • @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!

  • @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!?

  • @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.

  • @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..

  • @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?