Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Solidity Programming Essentials

You're reading from  Solidity Programming Essentials

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788831383
Pages 222 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Introduction to Blockchain, Ethereum, and Smart Contracts 2. Installing Ethereum and Solidity 3. Introducing Solidity 4. Global Variables and Functions 5. Expressions and Control Structures 6. Writing Smart Contracts 7. Functions, Modifiers, and Fallbacks 8. Exceptions, Events, and Logging 9. Truffle Basics and Unit Testing 10. Debugging Contracts 1. Other Books You May Enjoy Index

Transactions


A transaction is an agreement between a buyer and a seller, a supplier and a consumer, or a provider and a consumer that there will be an exchange of assets, products, or services for currency, cryptocurrency, or some other asset, either in the present or in the future. Ethereum helps in executing the transaction. Following are the three types of transactions that can be executed in Ethereum:

  • Transfer of Ether from one account to another: The accounts can be externally owned accounts or contract accounts. Following are the possible cases:
    • An externally owned account sending Ether to another externally owned account in a transaction
    • An externally owned account sending Ether to a contract account in a transaction
    • A contract account sending Ether to another contract account in a transaction
    • A contract account sending Ether to an externally owned account in a transaction
  • Deployment of a smart contract: An externally owned account can deploy a contract using a transaction in EVM.
  • Using or invoking a function within a contract: Executing a function in a contract that changes state is considered a transaction in Ethereum. If executing a function does not change a state, it does not require a transaction.

A transaction has some of the following important properties related to it:

  • The from account property denotes the account that is originating the transaction and represents an account that is ready to send some gas or Ether. Both gas and Ether concepts were discussed earlier in this chapter. The from account can be externally owned or a contract account.
  • Thetoaccount property refers to an account that is receiving Ether or benefits in lieu of an exchange. For transactions related to deployment of contract, thetofield is empty. It can be externally owned or a contract account.
  • Thevalueaccount property refers to the amount of Ether that is transferred from one account to another.
  • Theinputaccount property refers to the compiled contract bytecode and is used during contract deployment in EVM. It is also used for storing data related to smart contract function calls along with its parameters. A typical transaction in Ethereum where a contract function is invoked is shown here. In the following screenshot, notice the inputfield containing the function call to contract along with its parameters:
  • The blockHash account property refers to the hash of block to which this transaction belongs.
  • The blockNumber account property is the block in which this transaction belongs.
  • The gas account property refers to the amount of gas supplied by the sender who is executing this transaction.
  • The gasPrice account property refers to the price per gas the sender was willing to pay in wei (we have already learned about wei in the Ether section in this chapter). Total gas is computed at gas units * gas price.
  • The hash account property refers to the hash of the transaction.
  • The nonce account property refers to the number of transactions made by the sender prior to the current transaction.
  • The transactionIndex account property refers to the serial number of the current transactions in the block.
  • The value account property refers to the amount of Ether transferred in wei.
  • The v, r, and s account properties relate to digital signatures and the signing of the transaction.

A typical transaction in Ethereum, where an externally owned account sends some Ether to another externally owned account, is shown here. Notice the input field is not used here. Since two Ethers were sent in transaction, the value field is showing the value accordingly in wei as shown in the following screenshot:

One method to send Ether from an externally owned account to another externally owned account is shown in the following code snippet using web3 JavaScript framework, which will be covered later in this book:

web.eth.sendTransaction({from: web.eth.accounts[0], to: "0x9d2a327b320da739ed6b0da33c3809946cc8cf6a", value: web.toWei(2, 'ether')})

A typical transaction in Ethereum where a contract is deployed is shown in the following screenshot. In the following screenshot, notice the input field containing the bytecode of contract:

You have been reading a chapter from
Solidity Programming Essentials
Published in: Apr 2018 Publisher: Packt ISBN-13: 9781788831383
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}