0/5
## Signing a Transaction Object We've created our transaction object which is going to include the code for our Vyper contract. We're going to send it to the zero address because on the EVM world, that's how you deploy smart contracts. We're ready to go! Well, almost. What do we need to do? We need to sign it. Remember, that's how this whole blockchain thing works, you sign your transactions with your private key. So, we're going to use the web3 tooling to automatically sign this. We'll do: ```python w3.eth.account.sign_transaction(transaction, private_key='0x' * 64) ``` Now, as of right now, we don't have a private key, but I'm going to do something horrible that we're going to do just for now, and then I want you to never ever ever ever ever do this again. It's okay that we're doing it for now because we're using an Anvil private key, and these are very well known private keys. We're going to copy this private key and write it in our code. We're going to do: ```python PRIVATE_KEY = '0xac0974bec39a17e53ba78d40d28d4404b44facb478cbecde78ca4f704f7d74f7f2f80' ``` Then, down here, to sign our transaction, we're going to say: ```python signed_transaction = w3.eth.account.sign_transaction(transaction, private_key=PRIVATE_KEY) ``` Now, what we just did was something that, if you continue to do this, you will get destroyed in Web3. Just for stop. I don't make the rules. That is just what will happen, guaranteed, which was first off code our private key right into one of our scripts, and then number two, leave it in plain text. It's okay for right now because this is an Anvil private key, and these are well known publicly known private keys, so it's fine for now. But, we should never do this again, and I'll explain why in a minute. But, let's keep going. Let's do: ```python print(signed_transaction) ``` Let's even more cool about this is we just have a signed transaction, but we haven't actually sent it yet. We haven't sent it to the blockchain. It's literally just like sitting in our terminal here. Like, anybody could literally take this transaction, now that it's signed, and go execute it. So, additionally, you don't really want to have signed transactions lying around, so try not to do that, as well. But, p p p p p
A comprehensive guide to signing a transaction object using Web3.py. The lesson demonstrates the importance of signing transactions with private keys for blockchain security and shows how to implement this process in Python code.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on April 21, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on April 21, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar