BNB ETH BTC

All you need to know about - Transaction Signature


Have you ever wondered how transactions are 'signed'? I mean 'signing' a transaction - it sounds a bit strange, isn't it. Well technically it is not supposed to be as it is a cryptographic term. Let's understand how it is really done.

What is a Blockchain Transaction?

Before we get into the nitty gritty details, we must understand three key points -

  • A blockchain node is required to interact with the corresponding blockchain network
  • Blockchain is the single source of truth, i.e. if someone claims that their transaction is not processed, one can always verify it on the blockchain using the blockchain explorer in order to settle disputes
  • If you cannot setup a blockchain but still want to interact with blockchain, then you'll need to use services like 'Infura' which itself is connected to a blockchain node in it's backend

You might not have heard of infura but you might have heard about the Metamask wallet. Metamask interacts with blockchain using infura service in it's backend. That's how Metamask 'signs' Ethereum transactions. But what is a transaction? A transaction can be considered as a record of one account attempting to send some money (let's take the example of ETH) or tokens to another account. In every Ethereum transaction, there is a 'transaction object' that is being pushed to the blockchain. This transaction object is the 'main ingredient' of a block that forms a blockchain.

Ethereum

There are two main types of transactions - transactions from a contract account (smart contract transactions) and transactions from an external account (user to user transactions).  In general, each transaction object has got the following properties (we will discuss them in details in the coming sections):

  • from: 'from' account which sends the transaction, who is also responsible for all the payments
  • to: 'to' account, in case of crypto transfers (this is an optional field; smart contracts doesn't have this field)
  • value: amount of Ether to be send to the target address
  • gasPrice: amount of Ether the sender is willing to pay per unit gas to get this transaction processed
  • startGas/gasLimit: unit of gas that this transaction can consume
  • V,R,S: cryptographic hash value generated from the private key of an account that is used to sign the transaction
  • nonce: junk value that is used to mine a block (topic for another time)
  • data: this field is only present in smart contract transactions and it has the compiled bytecode of smart contracts to be executed in the blockchain

Smart contracts in Ethereum are written in Solidity language which is (though not exactly but is somewhat) similar to TypeScript version of JavaScript language. Solidity is popular among the Blockchain developers but there are other languages that can be used to write smart contract like Rust (Solana), C++ (EOS), JavaScript (Neo), etc.

Public Key, Private Key and (Ethereum) Account

We should understand these terms first in order to grasp the concept of transaction signature. Take Metamask for example. Within this wallet, there is an option to add account. Now what is this account that is added? Think of it like the email address which you can share with anyone. You can open your email account using it's password but no one else can.

Cardano

Similarly in the blockchain world, this password exists in the forms of private key & public key. Public key is generated as a one way function from the private key itself using the ECDSA (Elliptical Curve Digital Signature Algorithm) algorithm (One way function because public key is generated from the private key but the other way is not possible). And the account is generated by taking the last 20 bytes of the public key and hashing it through the KECCAK algorithm. That means, one can generate the public key and account using the private key alone. This is why a private key is the most important part of the three which one needs to safe guarded at all cost because if malicious actors gets a hold of it, one will permanently lose their account.

Signing a Transaction

How does the blockchain know whether it can transfer X ETH from account A to account B? I mean an account's balance can be found out by checking the sent & received transactions in the blockchain explorer but how does the network know that account owner of X is making the transaction or in other words, how does the blockchain verify the account ownership? Well it is accomplished by the signature of the transaction. And how is that done? Simple. Just by including the V, R, and S value (which we have seen above) within the transaction object.

DeFi

As mentioned before, the private key of an account is passed through a cryptographic algorithm which will spit out three equal hash values. What is the significance of this step? Well, the blockchain network will take the 'R' and 'S' part ('V' part is used for something else which we will not discuss here) of the signature and hash it through the ECRECOVER algorithm to generate the corresponding Ethereum account. Now if this account that is generated is same as the 'From' account, then the blockchain will know that the account owner is making the transaction.

Conclusion

Transaction signatures ensure authenticity of transactions. Signatures that is used to sign transactions are generated from the account's private key, where the account itself and the public key is generated from the private key. Due to this, the private key needs to be safe guarded at all cost and it is better kept somewhere offline out of reach of most of the people.

If you are planning to buy or trade crypto, I recommend giving the KuCoin exchange a try. They got some great offers for various coins in terms of lending and staking. Celsius is a good option if you want to safely earn returns on your crypto assets (referral links are enabled for both). Do check these out if you haven't already.

Couple of other articles which you might be interested in:

How do you rate this article?

100


Mishal Alexander
Mishal Alexander

Crypto Enthusiast | Budding Blockchain Developer |


What You Should Know
What You Should Know

Welcome to my blog, people.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.