Current location: Home > code > Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep37 Text
Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep37
Time: 2025-07-11 11:46:28 Source: Codora.ai Author: cpp Reading: 538 times
do weactually deploy this well we need toactually build our transaction becauseagain whenever we interact with theblockchain whenever we make a statechange and eminem 2024 newsin this case we'd bedeploying a contract we're going to makea state change so we first need to builda transaction sign a transaction andthen send a transaction and to do thatwe need to talk about that nuns thingagain remember way back in ourblockchain demo when we used a nuns tosolve the answer to that reallydifficult mining problem well thedefinition of nuns is just a word coinedor used for just one occasion and incryptography it's an arbitrary numberthat can be used just once in acryptographic communication so this nunsthat's used to find the answer is goingto be different from another nuns thatwe're actually going to need to make ourtransaction see if we look at ourmetamask and we look at our activity andwe look at one of the transactions we'vemade recently on ether scan if we scrolldown we'll see nuns here as well thisnuns is the number of transactions thatour account has actually made every timewe make another transaction ourtransaction is hashed with a new nutsthis is what's going on behind thescenes with our transaction and we needthis to send our transaction we canactually get our nuns by just grabbingour latest transaction count getlatest transaction we can do nuns equalsW3do.get transaction count and we'll putin my address this will give us thenumber of transactions and it'lleffectively give us ournuts we can even test it out with aprint python ploywe can see we can see that the answer iszero because on our local blockchainthis address that we're using hasn'tbeen used before we can even go to thetransactions tab we can see that thereare no transactions that have everoccurred on our local blockchain now todeploy this contract we need to make atransaction remember everything that wedo every time we change the state of ablockchain we're going to do it in atransaction let's create a transactionobject to do this we can dotransaction equals simple storage whichagain is this contract object dotConstructor do build transaction now asyou might have pointed out our simplestorage. doesn't actually have aConstructor every contract technicallyhas a Constructor this one's is justblank we're not telling our simplestorage. soul to do anything we saw backin our fundme example that the fundmeexample does have a Constructor so nowwe want to put in some parameters forthe transaction in web 3.i we alwayshave to give at least a couple ofparameters we always have to give thechain ID which we already got from abovewhich is1337 so we can just do chainID we need a from address in thiscase myaddress and then we need anuns which in our case is just nutsgreat now we have a transaction objectlet's even print this out and see whatit lookslike whoa what's this we can see there'seven more parameters in here than justwhat we made so we have value which isThe Ether or the ethereum that we'regoing to send we have gas we have ourgas price which we could arbitrarily setif we'd like we have the chain ID wehave from address we have the nuns andthen we have this giant data object andthen two is just empty because it'ssending it to the blockchain this giantdata object here is encompassingeverything that's happening in thissimple storage. Soul now that's just atransaction and anybody could actuallysend this transaction as long as it'ssigned by them so we have thistransaction but we need to sign it fromsomebody since we're sending it from ouraddress our private key is going to bethe only key that's going to work tosign this remember back when we weretalking about public and private Keys weright now have a message that isdefining how to deploy simple storagebut it's not signed yet so we're goingto need to use our private key to signit to create this unique messagesignature that we're the only ones thatcan create the private key but anybodyelse can verify that it was us whosigned it so now signed transactionequals web 3.e. account doigntransaction and the parameters it takesare going to be transaction and thenprivate keysay the private key equals private keybecause above we've actually gone aheadand added our private key in here nowguys a really really important noteabout putting a private key in your codethis is really bad practice if you pushthis to Source or you push this toGitHub somebody else can see a privatekey and steal all your funds so we don'twant to hardcode our private keys in ourcode like we're doing here so let's takethis time to talk about environmentvariables and how to set themenvironment variables are variables thatyou can set and that we set in ourterminal and in our Command lines thefollowing is a way to set an environmentvariable in Mac OS and Linux only don'tworry we'll show a way to make anenvironment variable in Windows as wellyou can set an environment variable byrunning something likeexport private key equals and thenadding whatever variable that youwant now if you typeEcho dollar sign private keythis variable actually shows up to setenvironment variables with Windows theprocess that we're going to do isactually a little bit different I'veleft a link in our GitHub to actuallyset environment variables in a Windowssetting and we've left a couple ofreally helpful links for working morewith environment variables you shoulddefinitely check them out it's importantto note that this export method thatwe're doing here for creatingenvironment variables only works for theduration that our shell is live so if wewere to close out of our shell and thenreopen it our environment variable thatwe set would be gone we'd have to rerunthat export command we're going to showyou a way to set environment variablesso that you don't have to keep doingthat now it's also not great to have inPL text on your computer however it's alot better than hardcoding it into ourscript here now remember if you're usingan account that has real money in itwhich I highly recommend you do not dodon't send this environment variable orthis private key or any of this codeanywhere because then people can
(Editor in charge: kotlin)
Latest content
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep187
- ·Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep132
- ·GenAI Essentials – Full Course for Beginners - Ep56
- ·Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep12
- ·Web3 Developer in 2024 Roadmap_ Solidity, Smart Contract, and Blockchain Development [Full Course] - Ep9
- ·GenAI Essentials – Full Course for Beginners - Ep168
- ·GenAI Essentials – Full Course for Beginners - Ep96
- ·Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep62
- ·Web3 Developer in 2024 Roadmap_ Solidity, Smart Contract, and Blockchain Development [Full Course] - Ep25
- ·GenAI Essentials – Full Course for Beginners - Ep150
Hot content
- ·GenAI Essentials – Full Course for Beginners - Ep48
- ·GenAI Essentials – Full Course for Beginners - Ep193
- ·Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial - Ep36
- ·Web3 Incorporation in Panama (A Legal Guide) - Ep3
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep65
- ·Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka - Ep35
- ·Psycho Killer _ Interview with a Killer S2 E1_ Gary Hilton - Ep1
- ·GenAI Essentials – Full Course for Beginners - Ep175
- ·Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript – 32-Hour Course - Ep103
- ·GenAI Essentials – Full Course for Beginners - Ep13