Creating Auction

Learn how to implement smart contract interactions in Solidity.

In this chapter, we'll continue learning Solidity and cover a few more advanced topics. Firstly, we'll learn about payments, how to receive payments in smart contracts, and how smart contracts can send payments to other smart contracts or users. Secondly, we'll learn about smart contract interactions and see how smart contracts can call methods on other smart contracts. Finally, we'll learn about events, a way to send real-time updates from smart contracts.

To make this chapter practical, we'll develop a new smart contract using all the new features we'll learn. We'll implement an auction contract allowing users to bid on buying an auction item. Every user will be able to make a bid in Ether, and the user that sends the highest bid will receive the ownership of this sold item when the auction is finished.

Implementing an auction item

In this chapter, we'll implement two new contracts:

  • Auction: This will implement the auction logic.

  • Ownable: This will represent the item being sold at the auction.

Let’s start by implementing the Ownable contract. It will only have two state fields:

  • owner: This is the address of the owner of this smart contract.

  • itemName: This is an arbitrary string name of the item being sold.

Get hands-on with 1200+ tech skills courses.