# RWA Marketplace

The `RWAMarketplaceSDK` class is designed to interact with a smart contract to manage real-world asset (RWA) transactions. It provides methods to:

* Connect to the smart contract using a signer or provider.
* List a new RWA.
* Fetch an RWA by its ID.
* Make, cancel, accept, and reject offers on RWAs.
* Approve offers as a middleman.
* Get offer count for an RWA.
* Get active RWA IDs.

**Class: `RWAMarketplaceSDK`**

**Constructor**

`private constructor(signerOrProvider: Signer | Provider)`: Initializes the SDK with a signer or provider.

**Static Methods**

* `static async connect(wc: WalletClient): Promise<RWAMarketplaceSDK>`: Connects to the RWAMARKETPLACE contract using a Reown `WalletClient` and returns an instance of `RWAMarketplaceSDK`.

**Instance Methods**

* `async listRWA(meta: Metadata): Promise<ethers.providers.TransactionResponse>`: Lists a new RWA with the given metadata.
* `async getRWA(id: number): Promise<RWA>`: Fetches an RWA by its ID and returns its details.
* `async makeOffer(id: number, amount: bigint): Promise<ethers.providers.TransactionResponse>`: Makes an offer on an RWA in $TALK.
* `async cancelOffer(id: number, idx: number): Promise<ethers.providers.TransactionResponse>`: Cancels a specific offer made by the caller.
* `async rejectOffer(id: number, idx: number): Promise<ethers.providers.TransactionResponse>`: Rejects a non-accepted offer.
* `async acceptOffer(id: number, idx: number): Promise<ethers.providers.TransactionResponse>`: Accepts an offer
* `async approveOffer(id: number): Promise<ethers.providers.TransactionResponse>`: Approves an accepted offer (middleman).
* `async getOfferCount(id: number): Promise<number>`: Retrieves the total number of offers for a given RWA.
* `async getOffer(id: number, idx: number): Promise<Offer>`: Retrieves a specific offer by its index for a given RWA.
* `async getActiveRWAIds(): Promise<number[]>`: Retrieves a list of IDs for all active RWAs.

**Types**

* `Metadata`: Defines the structure for RWA metadata, including title, description, image, tags, and category.
* `RWA`: Defines the structure for RWA data, including metadata, owner, and status.
* `Offer`: Defines the structure for offer data, including buyer, amount, and status flags.
* `ListingStatus`: An enum representing the status of an RWA listing (Active, PendingApproval, Sold).

Usage Example

```javascript
import { WalletClient } from "@reown/appkit";
import { RWAMarketplaceSDK } from "@cryptalk";

// Connect a Reown WalletClient
const wc = new WalletClient();
await wc.connect();

// Initialize the RWAMarketplaceSDK
const rwaMarketplace = await RWAMarketplaceSDK.connect(wc);

// Example: Listing a new RWA
const metadata = {
  title: "Example Asset",
  description: "Description of the asset",
  image: "https://example.com/image.jpg",
  tags: ["tag1", "tag2"],
  category: "Category",
};

const listTx = await rwaMarketplace.listRWA(metadata);
console.log("RWA Listed:", listTx.hash);

// Example: Getting an RWA by ID
const rwa = await rwaMarketplace.getRWA(0);
console.log("RWA Details:", rwa);

// Example: Making an offer
const amount = BigInt(100); // in TALK
const offerTx = await rwaMarketplace.makeOffer(0, amount);
console.log("Offer Made:", offerTx.hash);

```


---

# 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://cryptalks-organization-1.gitbook.io/cryptalk-sdk/rwa-marketplace.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.
