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... - Наука та технологія
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!
Really glad to hear that...thanks for the feedback, and will do!
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.
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.
Thanks for great series! Learning a lot, following along. Keep making awesome videos!
Thanks Mahima! Really glad to hear that : )
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.
Literally this is the best tutorial about Truffle. You made my day! Thanks💌
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
Thanks Matteo! I feel your pain brother - i think it took me 3 days to deploy my first contract to mainnet successfully lol.
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.
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.
Glad to help out brotha! Thanks for the sub.
👏👏👏👏👏👏 Excellent tutorial, thank you so much for this. Appreciate you man👍
very nice explanation . Got to know how to work with truffle and test network
best tutorial so far, thank u so much :D
You're A Class man!! Keep it up, thank you
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.
It took me 3 days too the first time I deployed to mainnet : ) Glad it was helpful!
Huge thanks! Great video!
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 ❤
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.
Great video thank you!
Bro You are amazing. You are the best. You make best videos.
Thanks Syed...I appreciate that my brotha!
Thanks a lot! it is helpful!
Thank you! Subbed :*
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.
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.
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.
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
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.
cool vid! ✅
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.
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.
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
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!!!!
Thanks bro
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?
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.
Thanks!
"@truffle/hdwallet-provider": "^2.0.1",
Why do we still want truffle? If we can use only web3 to deploy and interact with contract.
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
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.
Hello can you please tell blockchain developer roadmap for freshers
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!!
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
@@BlockExplorerMedia thanks for replying and looking forward to the course
Great stuff but when I try to get ether from faucet it throws an error that there is not sufficient gas * value ... any idea?
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/
@@BlockExplorerMedia Thank you so much for quick reply :D It worked (kovan network from the link that you sent)
Great
can you upload the vending machine test JS file to your github? im getting errors when trying to run tests
did you get that solved because i got errors too
@@nassaubahamas8570 no
New version of truffle does not init with migration files
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
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?
Hi Drake, were you able to run truffle test?? I am getting error
can you please help
Yes, I can run the truffle test by using the default local network with the ganache running
Thanks for replying mate,
I made a spelling mistake 🤦
@@jatin3709 prefer truffle than hardhat so far, I also pushed to Sepolia testnet too. Pretty easy.
Can u pls show us to read and write to these contracts using react js frontemd
Please see any of my 'Web3' tutorials - I have some using web3js and 1 (faucet UI) that uses Ethersjs. Cheers!
Is deploying on eth2 with infura different? Because infura menu is now different and I get error while deploying
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(?)
@@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
I read more about the merge, I think that Rinkeby and Ropstein are now deprecated, probably only goerli works now
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!
@@BlockExplorerMedia thank you for your amazing UA-cam channel 😍
why did you use 2 private keys, not 1 ? which is the first acc
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.
Why do we need two private keys from the metamask?
I don't remember why I used 2 in this video - an array of 1 should work fine.
@@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.
What happened when same contract deploy two or three times with same code and same information?
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.
@@BlockExplorerMedia means every time new smart contract address generated? Even using same code and same information and same Metamask address for deploy?
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.
@@BlockExplorerMedia thank you for reply.
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
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/
my create new project on infura is different and ethereum is replaced with web3
Unfortunately the UIs change pretty frequently....a moving target for sure.
1) Contract: VendingMachine
allows donuts to be purchased:
ReferenceError: account is not defined
I am stuck here XD
How to Deployed smartcontract on DogeChain?
Not sure, I haven't worked with Doge Chain yet. Would be interesting. Maybe I will look into it if time allows!
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!?
470
youasregod
noob
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.
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 } }
}
rinkeby: {
provider: () => new HDWalletProvider({
privateKeys: private_keys,
providerOrUrl:'**********proposital****',
numberOfAddress: 2
}
),
network_id: 4,
gas: 5500000,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
Change your network_id to 4, got the same error. it will work..
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?