# Interact With Your Smart Contract

## With blockchain explorer

With verified contracts on blockchain explorer, we can easily interact with them via blockchain explorer UI.

<https://testnet.u2uscan.xyz/address/0x8D51395C76C34d0e11178c1F7EE3219B4b958e30/read-contract#address-tabs><br>

## Read contract

Public fields of the contract:

```
uint public unlockTime;
address payable public owner;
```

They are displayed on the explorer, at `Read contract` tab:

<figure><img src="https://13370880-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkSNqP0Gff8h2fXgaMlEL%2Fuploads%2FZxpq4zOMWgpKghfbc9ll%2Fimage.png?alt=media&#x26;token=fe6ce00e-9869-4d1a-b8e6-6ebc572f4d30" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Public fields and view functions are displayed on the explorer.
{% endhint %}

### Write contract

Contract have a function:

```
function withdraw() public {}
```

Since it is publicly set, user can interact with this function via explorer's UI:

<figure><img src="https://13370880-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkSNqP0Gff8h2fXgaMlEL%2Fuploads%2FawAGRfc4lNGbHbyrX3rB%2Fimage.png?alt=media&#x26;token=65dead34-a2c1-4fda-9e74-7009ca39326b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To interact with contract, you have to connect your wallet to the explorer.
{% endhint %}

## With Hardhat

The same as above method, we will call `withdraw()` on `Lock` contract.

Back to your sample project, at `scripts` folder, add following `withdraw.ts` file:

```
import { ethers } from "hardhat";
import { Lock } from "../typechain-types";

async function main() {
    const [owner] = await ethers.getSigners();

    const lockAddr = "0x8D51395C76C34d0e11178c1F7EE3219B4b958e30"
    const Lock = await ethers.getContractFactory("Lock")
    const lock = await Lock.attach(lockAddr) as Lock

    const tx = await lock.withdraw()
    console.log("Withdrawal has completed. Transaction hash: " + tx.hash)
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});
```

Then run it by:

```
npx hardhat run scripts/withdraw.ts --network nebulas
```

And the result:&#x20;

{% code overflow="wrap" %}

```
Withdrawal has completed. Transaction hash: 0x0481a1abccb0e3dc336ec970628c033d11af6696da5536838ac76cad5f0494d7
```

{% endcode %}

## With a frontend and web3.js

Please head to next section [Integrate Your Smart Contract With a Frontend](https://docs.u2u.xyz/for-developers/smart-contract-development/interact-with-your-smart-contract).
