# Example - Write a function

We will use a smart contract from Goerli testnet.\
If you don't have any ETH on Goerli, get some from [our faucet](https://web3-wallet-manager.bubbleapps.io/version-test/goerly_faucet) for fees.\
\
Contract used

```
0x399F1A6D5f2e67978E1D36B9F093A34526ed720F
```

#### This demo is available [here](https://web3-demo.bubbleapps.io/version-test/write_contract)

To get started, open the contract on [Goerli etherscan](https://goerli.etherscan.io/)\
It has a function called samplePay, this is the one we need

<figure><img src="https://163529783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGXQwv3RyfW5Yi0SKag6n%2Fuploads%2FtfouiWq1TAksFWloiUxf%2FScreenshot%202022-12-07%20at%2021.35.43.png?alt=media&#x26;token=bbbbea5d-6c62-4029-85da-94d2f0117e79" alt=""><figcaption></figcaption></figure>

*All these parameters doesn't do anything, it is needed only for our demo.*

### Parameter 1

It requires a string that represents a name

```
Alex
```

### Parameter 2

It is a number, all parameters fields in plugin are of string type but it will auto convert to number if it detects one.

```
30
```

### Parameter 3

It requires a bool (true,false), again the plugin will detect if this is a true false parameter and will convert it to bool automatically.

```
true
```

### Transaction Value

Min payment for this contract is 0.001 ETH, so just set this number without converting to wei

```
0.001
```

This is how it looks:

<figure><img src="https://163529783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGXQwv3RyfW5Yi0SKag6n%2Fuploads%2F38bCD59tKyeBJETZG2bY%2FScreenshot%202022-12-07%20at%2021.51.43.png?alt=media&#x26;token=1019587b-6c50-4e35-9184-74f688aca8b6" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Do not forget to set the contract [ABI](https://docs.novabloq.com/web3-metamask/elements-details/smart-contract-read#more-about-abi)
{% endhint %}

### Result

First thing you have to do to make sure the tx was sent successfully is to save the transaction hash as soon as it is available, to avoid situations when the user refresh or closes the page.\
Use the event "[***Transaction ID is ready***](https://docs.novabloq.com/web3-metamask/elements-details/web3-and-metamask/..#common-events)" and get the transaction hash from state "[***Transaction Hash ID***](https://docs.novabloq.com/web3-metamask/elements-details/web3-and-metamask/..#common-states)"<br>

Example:

<figure><img src="https://163529783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGXQwv3RyfW5Yi0SKag6n%2Fuploads%2Fhx6466DWbbdWHpYTMU0T%2FScreenshot%202022-12-07%20at%2022.02.07.png?alt=media&#x26;token=72093d26-5467-46d8-b4e5-e8aa4f01e289" alt=""><figcaption></figcaption></figure>

To check if a transaction was successfully confirmed use the [Get Transaction confirmation](https://docs.novabloq.com/web3-metamask/elements-details/web3-utils/get-transaction-confirmations) action from the Utils element.<br>

Additionally, you can use the event "[*Transaction Sent Successfully*](https://docs.novabloq.com/web3-metamask/elements-details/web3-and-metamask/..#common-events)" for the cases when user doesn't close or refresh the page.

{% embed url="<https://discord.gg/HWfg853N6d>" %}
Our team is active on Discord. Join for discussions and support
{% endembed %}
