# Interacting with Smart Contracts Using ethers.js
Learn how to interact with smart contracts deployed on **Status Network** from a frontend using **ethers.js**.
In this tutorial, we'll walk through setting up a basic web application, deploying a smart contract on the **Status Network Testnet**, and interacting with it using **ethers.js**.
---
## Prerequisites
Before you begin, ensure you have the following:
- **MetaMask** installed in your browser.
- **Node.js** and **npm** installed on your computer.
- Basic understanding of **React.js** and how **blockchains** work.
### Set Up Status Network Testnet
1.**Add Status Network Testnet to MetaMask**:
- Follow the guide [Adding Status Network to MetaMask](/general-info/add-status-network) to add the testnet network to your wallet.
2.**Obtain Test ETH**:
- Use the [Status Network Testnet Faucet](/tools/testnet-faucets) to get test ETH for deploying and interacting with contracts.
3.**Bridge Assets (Optional)**:
- If needed, bridge assets to the Status Network Testnet using the [Testnet Bridge](/general-info/bridge/bridging-testnet).
---
## Smart Contract Deployment on Status Network
We'll use a simple smart contract called **BidBoard** for this tutorial. The contract allows advertisers to bid for space on an advertising board.
> **Note:** You can use your own smart contract if you prefer.
### Deploying the Contract
Follow the guide [Deploying a Smart Contract Using Remix](/tutorials/deploying-contracts/using-remix) to deploy the `BidBoard.sol` contract to the Status Network Testnet.
---
## Setting Up the Frontend Application
We'll create a React.js application to interact with the deployed smart contract.
### Step 1: Create a React App
Open your terminal and run:
```bash
npx create-react-app bidboard-ui
```
This command creates a new React application named `bidboard-ui`.
### Step 2: Install ethers.js
Navigate to the project directory and install **ethers.js**:
```bash
cd bidboard-ui
npm install ethers
```
---
## Building the Main Application Component
Open the project in your code editor and navigate to `src/App.js`.
### Import Required Libraries
Replace the content of `App.js` with the following code:
```jsx
importReact,{useState,useEffect}from"react";
import{ethers}from"ethers";
import"./App.css";
constApp=()=>{
// Contract details
constcontractAddress="YOUR_CONTRACT_ADDRESS";
constabi=[/* ABI JSON CODE */];
// State variables
const[currentAd,setCurrentAd]=useState("");
const[currentBid,setCurrentBid]=useState(0);
const[advertiser,setAdvertiser]=useState("");
const[newAd,setNewAd]=useState("");
const[bidAmount,setBidAmount]=useState("");
const[provider,setProvider]=useState(null);
const[status,setStatus]=useState("");
// Rest of the code...
};
exportdefaultApp;
```
> **Important:** Replace `"YOUR_CONTRACT_ADDRESS"` with the address of your deployed `BidBoard` contract. Paste the ABI of your contract in the `abi` array.
### Setting Up the Provider
Add the following code inside the `App` component to set up the provider:
Update the `return` statement in the `App` component:
```jsx
return(
<divclassName="app">
{/* Header */}
<header>
<h1>BidBoard</h1>
<p>Status:{status}</p>
</header>
{/* Current Advertisement */}
<sectionclassName="current-ad-section">
<h2>CurrentAdvertisement</h2>
<pclassName="ad-message">"{currentAd}"</p>
<pclassName="ad-details">
<strong>Advertiser:</strong>{advertiser}
</p>
<pclassName="ad-details">
<strong>CurrentBid:</strong>{currentBid}ETH
</p>
</section>
{/* Submit a New Bid */}
<sectionclassName="new-bid-section">
<h2>SubmitaNewBid</h2>
<input
type="text"
value={newAd}
onChange={(e)=>setNewAd(e.target.value)}
placeholder="Your Ad Message"
/>
<input
type="number"
value={bidAmount}
onChange={(e)=>setBidAmount(e.target.value)}
placeholder="Bid Amount in ETH"
/>
<buttononClick={submitBid}>SubmitBid</button>
</section>
{/* Footer */}
<footer>
<p>
<a
href="https://github.com/your-repo"
target="_blank"
rel="noopener noreferrer"
>
GitHubRepository
</a>
</p>
</footer>
</div>
);
```
---
## Styling the Application
Create a `App.css` file in the `src` directory and add your preferred styles. Here's a basic example:
```css
.app{
text-align:center;
font-family:Arial,sans-serif;
}
header{
background-color:#282c34;
padding:20px;
color:white;
}
section{
margin:20px;
}
input{
margin:5px;
padding:10px;
width:200px;
}
button{
padding:10px20px;
}
footer{
margin-top:40px;
}
```
---
## Running the Application
In your terminal, navigate to your project directory and run:
```bash
npm start
```
This command starts the development server. Open [http://localhost:3000](http://localhost:3000) in your browser to view the application.
---
## Testing the Application
1.**View Current Advertisement**:
- The application should display the current ad message, advertiser address, and current bid.
2.**Submit a New Bid**:
- Enter a new ad message and a bid amount higher than the current bid.
- Click **"Submit Bid"**.
- MetaMask will prompt you to confirm the transaction.
- Wait for the transaction to be confirmed.
3.**Observe Real-Time Updates**:
- Upon confirmation, the application should automatically update with the new ad, advertiser, and bid amount.
---
## Conclusion
You've successfully created a web application that interacts with a smart contract deployed on the Status Network Testnet using **ethers.js**. This tutorial covered:
- Setting up a React application.
- Deploying a smart contract to the Status Network.
- Connecting the frontend to the smart contract using ethers.js.
- Handling user interactions and real-time updates via events.