Payments in Smart Contracts

Learn how to implement, receive, and send payments in Ethereum smart contracts.

One of the most powerful features of Ethereum smart contracts is their seamless integration with accepting and sending payments. In this lesson, we'll get an introduction to working with payments in Solidity. First, we'll learn how smart contracts can accept payments, and then we'll see how smart contracts can send payments to Ethereum users or other smart contracts.

Accepting payments

A smart contract can accept payments from other smart contracts or Ethereum users. There are two ways for an Ethereum user to send payments to a smart contract:

  • Send the payment to the smart contract’s address. This is the same as sending Ether to another Ethereum user. We saw how to do this early on in this course when we used MetaMask to send test Ether to another account.

  • Send some amount of Ether when calling a smart contract method. Not all methods can accept payments in Solidity. A developer needs to explicitly specify which methods can receive payments.

Payable methods

To define a function that can receive payments, we need to add the payable modifier to it. A function can’t have the view or pure modifiers if it has the payable modifier.

Get hands-on with 1200+ tech skills courses.