Skip to main content

Web 3 Provider / Signer

πŸšͺ Prequisite Knowledge (Optional)

UploadNeeds Into Progressknow about Web 3 Architecture.

❓ Key Question / Problem / Issue

  1. What is the difference between Provider and Signer?
  2. What is the types of providers and signers.

βœ… Expected Output/Definition of Done

an article explaining provider, signer, and different kinds of API to use it.

🎁 Resulting Solution

To connect to a node in the blockchain and perform transactions, you need two things:

  • A connection to the Ethereum network (a Provider)
  • Holds your private key and can sign things (a Signer)

Provider

Provider is an abstraction of a connection to the Ethereum network, providing a concise, consistent interface to standard Ethereum node functionality.

The most common providers are:

  • JsonRpcProvider
  • Web3Provider

If you are in a browser the most common way to connect to a node is to use the provider given by the browser extension MetaMask. The ethers documentation explains very simply how to connect to ethereum using MetaMask with the Web3Provider.

If you are using ethers elsewhere, whether it’s in game or CLI, it's more than likely that you will use the JsonRpcProvider. To use it, you only need the url given by the node provider. The docs have also explains clearly how to use the JsonRPCProvider.

We can connect the provider to a specific node. A node can be local, or provided by web API like Infura or Alchemy. More about web API:

Backend API libraries | ethereum.org

Signer

Signer is an abstraction of an Ethereum Account, which can be used to sign messages and transactions and send signed transactions to the Ethereum Network to execute state changing operations.

The most common Signers you will encounter are:

  • [Wallet](Blockchain Wallet 4feacbb151684fb3b56896d033430507.md), which is a class which knows its private key and can execute any operations with it
  • JsonRpcSigner, which is connected to a JsonRpcProvider (or sub-class) and is acquired using getSigner
  • Web3Signer, which is connected to a Web3Provicer and is acquired using signer()