# Smart Contract Requests

## Prerequisites

For this section, you will need:

* A user's Theta Network wallet address, see the previous page on how to obtain this
* A web3 library installed, such as [ethers.js](https://www.npmjs.com/package/ethers), and connected to the Theta Mainnet RPC endpoint
* [web3-react](https://www.npmjs.com/package/web3-react)
* The smart contract address(es) of your event

## Checking ownership of a ticket

{% tabs %}
{% tab title="React TSX" %}

```tsx
import { useWeb3React } from '@web3-react/core'

const { library } = useWeb3React()

async function getTicketContractBalance(ticketAddress: string, library: any) {
  return library.getBalance(ticketAddress)
}
```

{% endtab %}
{% endtabs %}

## Stamping a ticket

This requires a smart contract interaction, and therefore will cost gas. You will need to [obtain an intstance of ticket contract](/quick-start/miscellaneous.md#getting-a-smart-contract-instance-with-ethers) first.

```tsx
import { BigNumber, ethers } from 'ethers'

const { library, account } = useWeb3React()

const ticketAddress = "..."
const ticketId = "..."
const TicketABI = "..." // you can get the ABI from the reference document

const TICKET_CONTRACT = getContract(ticketAddress, TicketABI, library, account)

const GAS_MARGIN = BigNumber.from(1000)

function calculateGasMargin(value: BigNumber, margin: BigNumber) {
  const offset = value.mul(margin).div(BigNumber.from(10000))
  return value.add(offset)
}

const handleStamp = () => {
  if (ticketAddress && ticketId !== undefined && TICKET_CONTRACT) {
    let estimate = TICKET_CONTRACT.estimateGas.stampTicket;
    let method = TICKET_CONTRACT.stampTicket;
    const ticketIdBN = BigNumber.from(ticketId)
    let args = [
      ticketIdBN
    ];
    let value = ethers.constants.Zero
    return estimate(...args, { value }).then((estimatedGasLimit: any) => {
      return method(...args, {
        value,
        gasLimit: calculateGasMargin(estimatedGasLimit, GAS_MARGIN)
      })
    }).then((tx: any) => {
      return true
    }).catch((e: Error) => {
      console.log(e.message)
      return false
    })
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.metapass.world/quick-start/smart-contract-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
