Deploy Your Smart Contract to Anvil

Noah Hein
InstructorNoah Hein
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

We deploy our smart contract to the local Anvil server running in the background on our machine. After we deploy the contract, we will look over some of the logging that Anvil produced for us.

Noah Hein: [0:00] To deploy our smart contract, we are going to use Forge. Forge will deploy our contract on to our Anvil server that's running in the background. [0:09] To do that, we're going to do forge c. C is shorthand for create. Then we're going to need to pass in the private key that we copied over here, so make sure you have this copied. You can do forge c, and you will pass in the path to your contract. We'll do src/Contract.sol and then a colon and the name of the contract that you want to deploy.

[0:40] You can only deploy one contract at a time using forge create. If you had multiple smart contracts within your Solidity file, you need to suffix it with this colon and then the name of the contract.

[0:55] After that, you need to give it a private key. This private key will be signing the traction, that is deploying this contract up to our chain. We'll be paying all of the gas fees that are associated with that.

[1:09] The other thing that we'll need to do is since our contract has a constructor, here you can see that we've got this constructor. That is not optional. We do need to pass that. That's another flag. We'll say -constructor-args and we'll pass 10 as the value.

[1:32] Awesome. You can see that we successfully deployed our contract. You can see that the deployer was the private key that we passed in. If you take a look here, you can see that our private key was f2ff80. Over here you can see that it is f2ff80. It's the same private key. That private key matches to this deployer, which is like the public key that matches our private key.

[2:14] You can see here that we used this to sign it, but it winds up being this b92266. It's what you see on chain. You can see a little bit of your private key and public key, and how they relate to each other there. Then, you can see that our contract was deployed to this address.

[2:35] It also gives us the transaction hash. You can see all this happening over here on Anvil. You can see that when we originally booted it up. There it is. You can see it runs a bunch of different commands here. Then it finally runs an eth_sendRawTransaction. You can see this transaction matches the same hash over here. You see it ends in 27b. Here you can see it ends in 27b as well.

[3:02] This is the contract that was created along with the block hash and everything. You can see that it is now successfully deployed up to the chain. We can begin interacting with it.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today