# Write Contract

## Link to the Smart Contract:&#x20;

{% embed url="<https://bscscan.com/address/0x572d9f2e8392cd36a6347384168c0b5bc5ab1a59#writeContract>" %}

### Buy

The method is used to purchase a specific auction.

<table data-header-hidden><thead><tr><th width="201.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>_buyNowId (uint256)</td><td>The ID of the auction to buy</td><td><ul><li>must be a valid auction ID</li><li>the auction must be active</li></ul></td></tr><tr><td>_tokenQuantity (uint256)</td><td>The number of tokens that we want to purchase.</td><td><ul><li>must be a positive number</li></ul></td></tr><tr><td>_referrer (address)</td><td>The address of the wallet from which we received the auction recommendation or the address of the person who registered us as an upline. If the user purchases the auction through a referral, the referrer will receive a commission from the transaction based on the agreed commission and referral level.</td><td><ul><li>must be an address</li></ul></td></tr><tr><td>_data (bytes)</td><td>Additional data, if needed.</td><td><ul><li>By default, it is set to 0x00</li></ul></td></tr></tbody></table>

**Transaction Example**

{% embed url="<https://testnet.bscscan.com/tx/0xb559a00dc815b4f5205a422cfc3a72381febaa59cb13835ff0b57d69da8ece3d>" %}
The participant who Bought a token:&#x20;
{% endembed %}

<figure><img src="https://t26441698.p.clickup-attachments.com/t26441698/f5efbd8b-f467-4359-a6fa-11f19b9de83c/image.png" alt=""><figcaption></figcaption></figure>

**a. Money from the buyer sent to the Contract**

**b. Money sent from the Contract to** Level 1 money Referral send

**c. Money sent from the Contract to** Level 2 money Referral send

**d. Money sent from the Contract to** Level 3 money Referral send

**e. Money sent from the Contract to** the Contract Fee address

**f. Money sent from the Contract to** the Auction operator

**g. Token Transfered FROM:** Address from where the token was sent

**h. Token Transferred To:** Address where the Token is sent

**i. Token Transferred:** ERC-1155 standard of the token

**j. Token Transferred:** Amount of tokens

**k. Token Transferred:** Token ID \[number of the token ID]

**l. Token Transferred:** Token Contract Address

### closeAuction

The method allows the contract owner or the operator of the auction to close the auction and collect tokens and funds from it. It is also used to withdraw the proceeds from a completed auction. The method is designed to handle various aspects of auction management, such as closing auctions prematurely, collecting tokens, and managing the distribution of auction assets. This functionality provides flexibility and control over the auction process, ensuring a smooth and efficient experience for both the auction participants and the contract operator.

<table data-header-hidden><thead><tr><th width="219.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>_buyNowId (uint256)</td><td>The ID of the auction to be closed/collected.</td><td><ul><li>must be a valid auction ID</li></ul></td></tr><tr><td>_data (bytes)</td><td>Additional data, if needed.</td><td><ul><li>By default, it is set to 0x00</li></ul></td></tr></tbody></table>

**Transaction Example:**

{% embed url="<https://testnet.bscscan.com/tx/0x531138ee3336e55f8994140e64f0e5fb41209ca9afff457712d23f95294da5e1>" %}
The operator claims unsold tokens from the Contract&#x20;
{% endembed %}

<figure><img src="https://t26441698.p.clickup-attachments.com/t26441698/f98cee32-0da6-48d4-ae34-26d3bca12194/image.png" alt=""><figcaption></figcaption></figure>

**a. Token Transfered FROM:** Address from where the token was sent

**b. Token Transferred To:** Address where the Token is sent

**c.Token Transferred:** ERC-1155 standard of the token

**d. Token Transferred:** Amount of tokens (number of tokens sent back)

**e. Token Transferred:** Token ID \[number of the token ID]

**f. Token Transferred:** Token Contract Address

**Transaction Example:**

{% embed url="<https://testnet.bscscan.com/tx/0xf48742a05a22a66cc3d2f6d3a56accd70975c96401089083b77d4908d239d5ee>" %}
The operator closes the auction before the start&#x20;
{% endembed %}

<figure><img src="https://t26441698.p.clickup-attachments.com/t26441698/0b591517-c568-44e5-849d-9a301aff4009/image.png" alt=""><figcaption></figcaption></figure>

**a. Token Transfered FROM:** Address from where the token was sent

**b. Token Transferred To:** Address where the Token is sent

**c. Token Transferred:** ERC-1155 standard of the token

**d. Token Transferred:** Amount of tokens

**e. Token Transferred:** Token ID \[number of the token ID]

**f. Token Transferred:** Token Contract Address

### createAuction

The createAuction method in the smart contract is designed for initiating the creation of Buy Now auctions. It is necessary to have a Token in order to list an auction, which can be either acquired for resale purposes or self-generated.

<table data-header-hidden><thead><tr><th width="236.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>_tokenContractAddress (address)</td><td>The address of the token contract where the token is located and will be listed for sale.</td><td><ul><li>must be a Token Contract Address</li></ul></td></tr><tr><td>_tokenId (uint256)</td><td>The ID of the token to be listed for sale in the auction.</td><td><ul><li>tokenID must be greater than 0</li><li>must be an owner of the token</li></ul></td></tr><tr><td>_tokenPrice (uint256)</td><td>The price set for a single token, expressed in the units of the specified token (e.g., 0.0001 BUSD is represented as 1e14 in our case).</td><td><ul><li>must be a positive number</li><li>possible min price 0.0001 BUSD</li></ul></td></tr><tr><td>_tokenQuantity (uint256)</td><td>The number of tokens to be sent for the auction.</td><td><ul><li>cannot be 0</li><li>cannot be greater than owned tokens</li></ul></td></tr><tr><td>_startBlock (uint256)</td><td>The block number at which the auction is scheduled to start.</td><td><ul><li>must be a blockchain block</li><li>must be lower than endBlock</li></ul></td></tr><tr><td>_endBlock (uint256)</td><td>The block number at which the auction is scheduled to end.</td><td><ul><li>must be a blockchain block</li><li>must be higher than startBlock</li></ul></td></tr><tr><td>_level1ReferralFee (uint256)</td><td>The amount of referral fee received by the person who refers the auction at level 1. Can be selected from 0 to 15% of the transaction amount. The sum of referral fees from all referrers cannot exceed 15%.</td><td><ul><li>can be set from 0 to 15% (1% = 100)</li><li>the max sum of the referral fee must be set to 15%</li></ul></td></tr><tr><td>_level2ReferralFee (uint256)</td><td>The amount of referral fee received by the person who refers the auction at level 2. Can be selected from 0 to 15% of the transaction amount. The sum of referral fees from all referrers cannot exceed 15%.</td><td><ul><li>can be set from 0 to 15% (1% = 100)</li><li>the max sum of the referral fee must be set to 15%</li></ul></td></tr><tr><td>_level3ReferralFee (uint256)</td><td>The amount of referral fee received by the person who refers the auction at level 3. Can be selected from 0 to 15% of the transaction amount. The sum of referral fees from all referrers cannot exceed 15%.</td><td><ul><li>can be set from 0 to 15% (1% = 100)</li><li>the max sum of the referral fee must be set to 15%</li></ul></td></tr><tr><td>_multipleDeposits (bool)</td><td>Specifies whether buyers can make multiple purchases in the auction.</td><td><ul><li>can be only <strong>true</strong> or <strong>false</strong></li><li>we can use "1" (true) or "0" (false)</li></ul></td></tr><tr><td>data (bytes)</td><td>Additional data, if needed.</td><td><ul><li>By default, it is set to 0x00</li></ul></td></tr></tbody></table>

<figure><img src="https://t26441698.p.clickup-attachments.com/t26441698/2c5ec94b-8179-4aaa-87a0-dad0a1dff206/image.png" alt=""><figcaption></figcaption></figure>

**a. Token Transfered FROM:** Address from where the token was sent

**b. Token Transferred To:** Address where the Token is sent

**c. Token Transferred:** ERC-1155 standard of the token

**d. Token Transferred:** Amount of tokens

**e. Token Transferred:** Token ID \[number of the token ID]

**f. Token Transferred:** Token Contract Address

### onERC1155BatchReveived

The onERC1155BatchReceived is a standard function within the ERC-1155 interface in the Solidity environment, similar to onERC1155Received. However, it is used to handle the batch (multiple) receipt of tokens by a contract. When an address receives a batch of tokens (either NFTs or MFTs) on its contract, if that contract includes the onERC1155BatchReceived method, it is automatically invoked. This allows the contract to respond to the receipt of multiple tokens in a single transaction and execute appropriate actions.

| **Data**             | **Description**                                                             | **Restrictions**                                |
| -------------------- | --------------------------------------------------------------------------- | ----------------------------------------------- |
| address (operator)   | The address performing the token batch transfer operation.                  | <ul><li>must be an address</li></ul>            |
| address (from)       | The address from which the tokens were sent.                                | <ul><li>must be an address</li></ul>            |
| uint256\[] (tokenID) | An array of token identifiers.                                              | <ul><li>must be a number</li></ul>              |
| uint256\[] (value)   | An array of amounts of received tokens corresponding to the respective IDs. | <ul><li>must be a number</li></ul>              |
| bytes                | Additional data passed along with the transfer operation.                   | <ul><li>By default, it is set to 0x00</li></ul> |

The onERC1155Received function returns a special four-byte code (bytes4), which serves as a confirmation that the contract successfully received the tokens. In summary, onERC1155BatchReceived allows a contract to react to the receipt of a batch of ERC-1155 tokens and execute specific actions in response to this batch event.

### onERC1155Received

The onERC1155Received function is a standard function within the ERC-1155 interface in the Solidity environment, concerning non-fungible tokens (NFTs) or multi-fungible tokens (MFTs). This function is designed to handle the receipt of tokens by a contract. When an address receives tokens (either NFTs or MFTs) on its contract, if that contract includes the onERC1155Received function, it is automatically invoked. This allows the contract to respond to the receipt of new tokens and execute appropriate actions.

<table data-header-hidden><thead><tr><th width="203.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>address (operator)</td><td>The address performing the token transfer operation.</td><td><ul><li>must be an address</li></ul></td></tr><tr><td>address (from)</td><td>The address from which the tokens were sent.</td><td><ul><li>must be an address</li></ul></td></tr><tr><td>uint256 (tokenID)</td><td>The token identifier.</td><td><ul><li>must be a number</li></ul></td></tr><tr><td>uint256 (value)</td><td>The ammount of received tokens.</td><td><ul><li>must be number</li></ul></td></tr><tr><td>bytes</td><td>Additional data passed along with the transfer operation.</td><td><ul><li>By default, it is set to 0x00</li></ul></td></tr></tbody></table>

The onERC1155Received function returns a special four-byte code (bytes4), which serves as a confirmation that the contract successfully received the tokens. In summary, onERC1155Received enables a contract to react to the receipt of ERC-1155 tokens and trigger specific actions in response to this event.

### renounceOwnership

* This method **allows the contract's owner** to renounce their ownership. This method is accessible only to the contract's owner.
* This function enables the current owner to renounce ownership of the contract. Once this method is called, the owner will lose their privileges to manage the contract, and any methods that require owner permissions will no longer be accessible.

### setBusdAddress

The setBusdAddress method allows the contract owner to update the address of the BUSD contract in the smart contract. This is important for connecting and interacting with the BUSD contract to perform operations such as token transfers, balance checks, and other financial transactions involving BUSD tokens. The owner can update the BUSD contract address if the contract is upgraded or replaced with a new version.

<table data-header-hidden><thead><tr><th width="221.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>newAddress (address)</td><td>The new address of the BUSD contract to be set.</td><td><ul><li>must be an address</li></ul></td></tr></tbody></table>

### setReferralAddress

The setReferralAddress method allows the contract owner to update the address of the referral contract in the smart contract. This is important for connecting and interacting with the referral contract to perform operations related to referral bonuses, commissions, or any other referral-related functionalities. The owner can update the referral contract address if the contract is upgraded or replaced with a new version or if they want to use a different referral contract for their application.

| **Data**             | **Description**                                     | **Restrictions**                     |
| -------------------- | --------------------------------------------------- | ------------------------------------ |
| newAddress (address) | The new address of the referral contract to be set. | <ul><li>must be an address</li></ul> |

### setRoyaltyAddress

The setRoyaltyAddress method allows the contract owner to update the address of the royalty contract in the smart contract. This is important for connecting and interacting with the royalty contract to perform operations related to royalty payments, revenue sharing, or any other royalty-related functionalities. The owner can update the royalty contract address if the contract is upgraded or replaced with a new version or if they want to use a different royalty contract for their application.

<table data-header-hidden><thead><tr><th width="224.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>newAddress (address)</td><td>The new address of the royalty contract to be set.</td><td><ul><li>must be an address</li></ul></td></tr></tbody></table>

### setTreasuryFee

This method is used to set the transaction fee in the contract. It is accessible only to the contract's owner.

<table data-header-hidden><thead><tr><th width="167.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>fee (uint256)</td><td>The amount of the transaction fee to be set.</td><td><ul><li>Only for the Contract owner</li><li>Must be a positive number</li></ul></td></tr></tbody></table>

### setTressuryAddress

The method is used to set the treasury address in the contract. The treasury address is the designated account where funds or tokens are stored for various purposes, such as collecting fees, managing reserves, or distributing rewards.

<table data-header-hidden><thead><tr><th width="222.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>newAddress (address)</td><td>The new treasury address to be set.</td><td><ul><li>You must be the Contract owner</li><li>Must be a wallet address</li></ul></td></tr></tbody></table>

### transferOwnership

The method is **available only to the current owner** **of the contract** and allows changing the ownership of the contract

<table data-header-hidden><thead><tr><th width="209.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Data</strong></td><td><strong>Description</strong></td><td><strong>Restrictions</strong></td></tr><tr><td>newOwner (address)</td><td>The address of the new contract owner.</td><td><ul><li>must be a wallet address</li></ul></td></tr></tbody></table>


---

# 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.metaproprotocol.com/developer-documentation/smart-contracts/metaprobuynow/write-contract.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.
