### Install @polymarket/builder-relayer-client Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Installs the builder-relayer-client package using pnpm. This is the first step to using the library in your project. ```bash pnpm install @polymarket/builder-relayer-client ``` -------------------------------- ### Basic RelayClient Setup with viem Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Initializes the `RelayClient` from the @polymarket/builder-relayer-client library using viem for wallet management. It demonstrates how to set up the client for both SAFE and PROXY transaction types. ```typescript import { createWalletClient, Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { polygon } from "viem/chains"; import { RelayClient, RelayerTxType } from "@polymarket/builder-relayer-client"; const relayerUrl = process.env.POLYMARKET_RELAYER_URL; const chainId = parseInt(process.env.CHAIN_ID); const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex); const wallet = createWalletClient({ account, chain: polygon, transport: http(process.env.RPC_URL) }); // Initialize the client with SAFE transaction type (default) const client = new RelayClient(relayerUrl, chainId, wallet); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, undefined, RelayerTxType.PROXY); ``` -------------------------------- ### RelayClient Setup with Local Builder Authentication Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Initializes the `RelayClient` with credentials for local builder authentication. This method uses `BuilderApiKeyCreds` and `BuilderConfig` from the @polymarket/builder-signing-sdk. ```typescript import { BuilderApiKeyCreds, BuilderConfig } from "@polymarket/builder-signing-sdk"; import { RelayerTxType } from "@polymarket/builder-relayer-client"; const builderCreds: BuilderApiKeyCreds = { key: process.env.BUILDER_API_KEY, secret: process.env.BUILDER_SECRET, passphrase: process.env.BUILDER_PASS_PHRASE, }; const builderConfig = new BuilderConfig({ localBuilderCreds: builderCreds }); // Initialize with SAFE transaction type (default) const client = new RelayClient(relayerUrl, chainId, wallet, builderConfig); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig, RelayerTxType.PROXY); ``` -------------------------------- ### RelayClient Setup with Remote Builder Authentication Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Initializes the `RelayClient` for remote builder authentication. This configuration uses `BuilderConfig` with remote signing service details, including URL and authentication token. ```typescript import { BuilderConfig } from "@polymarket/builder-signing-sdk"; import { RelayerTxType } from "@polymarket/builder-relayer-client"; const builderConfig = new BuilderConfig( { remoteBuilderConfig: { url: "http://localhost:3000/sign", token: `${process.env.MY_AUTH_TOKEN}` } }, ); // Initialize with SAFE transaction type (default) const client = new RelayClient(relayerUrl, chainId, wallet, builderConfig); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig, RelayerTxType.PROXY); ``` -------------------------------- ### Execute ERC20 Approval Transaction Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Demonstrates how to create and execute an ERC20 approval transaction using the `RelayClient`. It includes defining the `approve` function ABI and preparing the transaction data using viem. The example shows execution with both SAFE and PROXY transaction types. ```typescript import { encodeFunctionData, prepareEncodeFunctionData, maxUint256 } from "viem"; import { Transaction, RelayerTxType } from "@polymarket/builder-relayer-client"; const erc20Abi = [ { "constant": false, "inputs": [ {"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"} ], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function" } ]; const erc20 = prepareEncodeFunctionData({ abi: erc20Abi, functionName: "approve", }); function createApprovalTransaction( tokenAddress: string, spenderAddress: string ): Transaction { const calldata = encodeFunctionData({ ...erc20, args: [spenderAddress, maxUint256] }); return { to: tokenAddress, data: calldata, value: "0" }; } // Initialize client with SAFE transaction type (default) const safeClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig, RelayerTxType.PROXY); // Execute the approval - works with both SAFE and PROXY const approvalTx = createApprovalTransaction( "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // USDC "0x4d97dcd97ec945f40cf65f87097ace5ea0476045" // CTF ); // Using SAFE client const safeResponse = await safeClient.execute([approvalTx], "usdc approval on the CTF"); const safeResult = await safeResponse.wait(); console.log("Safe approval completed:", safeResult.transactionHash); // Using PROXY client const proxyResponse = await proxyClient.execute([approvalTx], "usdc approval on the CTF"); const proxyResult = await proxyResponse.wait(); console.log("Proxy approval completed:", proxyResult.transactionHash); ``` -------------------------------- ### getNonce() - Get Signer Nonce Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Retrieve the current nonce for a signer address to ensure proper transaction ordering for SAFE or PROXY transaction types. ```APIDOC ## getNonce() - Get Signer Nonce ### Description Retrieve the current nonce for a signer address to ensure proper transaction ordering. ### Method GET ### Endpoint (Implicitly called via `client.getNonce`) ### Parameters #### Query Parameters - **signerAddress** (string) - Required - The address of the signer for which to retrieve the nonce. - **transactionType** (TransactionType) - Required - The type of transaction (e.g., `TransactionType.SAFE`, `TransactionType.PROXY`). ### Request Example ```typescript // Assuming 'client' is an initialized RelayClient instance and 'wallet' is a valid wallet object const signerAddress = await wallet.account.address; // Get nonce for SAFE transactions const safeNonce = await client.getNonce(signerAddress, TransactionType.SAFE); console.log("Safe Nonce:", safeNonce.nonce); // Get nonce for PROXY transactions const proxyNonce = await client.getNonce(signerAddress, TransactionType.PROXY); console.log("Proxy Nonce:", proxyNonce.nonce); ``` ### Response #### Success Response (200) - **nonce** (object) - An object containing the nonce information. - **nonce** (number) - The current nonce for the specified signer address and transaction type. #### Response Example ```json { "nonce": 15 } ``` ``` -------------------------------- ### Get Signer Nonce with Polymarket Builder Relayer Client Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Retrieves the current nonce for a given signer address using the Polymarket Builder Relayer Client. This is essential for ensuring proper transaction ordering, especially for SAFE and PROXY transaction types. The function requires the signer's address and the transaction type. ```typescript import { RelayClient } from "@polymarket/builder-relayer-client"; import { TransactionType } from "@polymarket/builder-relayer-client"; const client = new RelayClient( "https://relayer.polymarket.com", 137, wallet, builderConfig ); const signerAddress = await wallet.account.address; try { // Get nonce for SAFE transactions const safeNonce = await client.getNonce(signerAddress, TransactionType.SAFE); console.log("Safe Nonce:", safeNonce.nonce); // Get nonce for PROXY transactions const proxyNonce = await client.getNonce(signerAddress, TransactionType.PROXY); console.log("Proxy Nonce:", proxyNonce.nonce); } catch (error) { console.error("Error fetching nonce:", error); } ``` -------------------------------- ### Initialize Polymarket RelayClient (TypeScript) Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Initializes a RelayClient instance for interacting with the Polymarket relayer. Supports both SAFE (default) and PROXY transaction types. Requires viem for wallet creation and builder-signing-sdk for authentication. ```typescript import { createWalletClient, Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { polygon } from "viem/chains"; import { RelayClient, RelayerTxType } from "@polymarket/builder-relayer-client"; import { BuilderApiKeyCreds, BuilderConfig } from "@polymarket/builder-signing-sdk"; // Setup wallet const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex); const wallet = createWalletClient({ account, chain: polygon, transport: http(process.env.RPC_URL) }); // Setup Builder authentication (optional) const builderCreds: BuilderApiKeyCreds = { key: process.env.BUILDER_API_KEY, secret: process.env.BUILDER_SECRET, passphrase: process.env.BUILDER_PASS_PHRASE, }; const builderConfig = new BuilderConfig({ localBuilderCreds: builderCreds }); // Initialize SAFE client (default) const safeClient = new RelayClient( "https://relayer.polymarket.com", 137, // Polygon chain ID wallet, builderConfig ); // Or initialize PROXY client const proxyClient = new RelayClient( "https://relayer.polymarket.com", 137, wallet, builderConfig, RelayerTxType.PROXY ); ``` -------------------------------- ### RelayClient Constructor Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Initialize a RelayClient instance to interact with the Polymarket relayer infrastructure. Supports both Gnosis Safe and Polymarket Proxy transaction types. ```APIDOC ## RelayClient Constructor ### Description Initialize a RelayClient instance to interact with the Polymarket relayer infrastructure with support for SAFE or PROXY transaction types. ### Method Constructor ### Endpoint N/A (Client-side library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { createWalletClient, Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { polygon } from "viem/chains"; import { RelayClient, RelayerTxType } from "@polymarket/builder-relayer-client"; import { BuilderApiKeyCreds, BuilderConfig } from "@polymarket/builder-signing-sdk"; // Setup wallet const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex); const wallet = createWalletClient({ account, chain: polygon, transport: http(process.env.RPC_URL) }); // Setup Builder authentication (optional) const builderCreds: BuilderApiKeyCreds = { key: process.env.BUILDER_API_KEY, secret: process.env.BUILDER_SECRET, passphrase: process.env.BUILDER_PASS_PHRASE, }; const builderConfig = new BuilderConfig({ localBuilderCreds: builderCreds }); // Initialize SAFE client (default) const safeClient = new RelayClient( "https://relayer.polymarket.com", 137, // Polygon chain ID wallet, builderConfig ); // Or initialize PROXY client const proxyClient = new RelayClient( "https://relayer.polymarket.com", 137, wallet, builderConfig, RelayerTxType.PROXY ); ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A (Constructor) ``` -------------------------------- ### Deploy Gnosis Safe with Polymarket Builder Relayer Client (TypeScript) Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Deploys a new Gnosis Safe contract for the configured signer. This method is only available for the SAFE transaction type. It requires wallet and builder credentials to be set up. The response includes the transaction hash and the newly deployed proxy address. ```typescript import { createWalletClient, Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { polygon } from "viem/chains"; import { RelayClient } from "@polymarket/builder-relayer-client"; import { BuilderApiKeyCreds, BuilderConfig } from "@polymarket/builder-signing-sdk"; const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex); const wallet = createWalletClient({ account, chain: polygon, transport: http(process.env.RPC_URL) }); const builderCreds: BuilderApiKeyCreds = { key: process.env.BUILDER_API_KEY, secret: process.env.BUILDER_SECRET, passphrase: process.env.BUILDER_PASS_PHRASE, }; const builderConfig = new BuilderConfig({ localBuilderCreds: builderCreds }); const client = new RelayClient( "https://relayer.polymarket.com", 137, wallet, builderConfig ); try { const response = await client.deploy(); const result = await response.wait(); if (result) { console.log("Safe deployed successfully!"); console.log("Transaction Hash:", result.transactionHash); console.log("Safe Address:", result.proxyAddress); } else { console.log("Safe deployment failed"); } } catch (error) { if (error.message === "SAFE_DEPLOYED") { console.log("Safe already deployed for this account"); } else { console.error("Deployment error:", error); } } ``` -------------------------------- ### Deploy Safe Contract with Builder Relayer Client Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Initializes the RelayClient with the SAFE transaction type and deploys a safe contract. Proxy wallets are deployed automatically on their first transaction. The function returns transaction details upon successful deployment. ```typescript const client = new RelayClient(relayerUrl, chainId, wallet, builderConfig); const response = await client.deploy(); const result = await response.wait(); if (result) { console.log("Safe deployed successfully!"); console.log("Transaction Hash:", result.transactionHash); console.log("Safe Address:", result.proxyAddress); } else { console.log("Safe deployment failed"); } ``` -------------------------------- ### execute() - Execute Transaction Batch Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Execute one or more transactions through the relayer. The client handles automatic batching and state tracking for the submitted transactions. ```APIDOC ## execute() - Execute Transaction Batch ### Description Execute one or more transactions through the relayer with automatic batching and state tracking. ### Method POST ### Endpoint `/execute` (Implicit, handled by the client library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **transactions** (Array) - Required - An array of transaction objects to be executed. - **description** (string) - Optional - A description for the batch of transactions. **Transaction Object**: - **to** (Hex) - Required - The address of the contract to call. - **data** (Hex) - Required - The encoded function call data. - **value** (Hex) - Optional - The amount of native currency to send with the transaction (defaults to '0'). ### Request Example ```typescript import { encodeFunctionData, prepareEncodeFunctionData, maxUint256 } from "viem"; import { Transaction } from "@polymarket/builder-relayer-client"; // Define ERC20 approve function const erc20Abi = [ { "constant": false, "inputs": [{"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"}], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "type": "function" } ]; const erc20 = prepareEncodeFunctionData({ abi: erc20Abi, functionName: "approve", }); // Create approval transaction function createApprovalTransaction(tokenAddress: string, spenderAddress: string): Transaction { const calldata = encodeFunctionData({ ...erc20, args: [spenderAddress, maxUint256] }); return { to: tokenAddress, data: calldata, value: "0" }; } // Execute transaction const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; const ctfAddress = "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"; const approvalTx = createApprovalTransaction(usdcAddress, ctfAddress); try { // Assuming 'client' is an initialized RelayClient instance const response = await client.execute([approvalTx], "USDC approval on CTF"); const result = await response.wait(); if (result) { console.log("Transaction completed!"); console.log("Transaction Hash:", result.transactionHash); console.log("Transaction ID:", result.transactionID); console.log("State:", result.state); } else { console.error("Transaction failed"); } } catch (error) { console.error("Execution error:", error); } ``` ### Response #### Success Response (200) - **transactionHash** (Hex) - The hash of the executed transaction. - **transactionID** (string) - A unique identifier for the relayer transaction. - **state** (string) - The current state of the transaction (e.g., 'pending', 'success', 'failed'). #### Response Example ```json { "transactionHash": "0xabc123...", "transactionID": "tx-12345", "state": "pending" } ``` ``` -------------------------------- ### Check Safe Deployment Status using TypeScript Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Verifies if a Gnosis Safe has been deployed at a given address. It takes the safe address as input and returns a boolean indicating deployment status. Requires initialization of a RelayClient with the relayer URL, chain ID, and wallet. ```typescript import { RelayClient } from "@polymarket/builder-relayer-client"; const client = new RelayClient( "https://relayer.polymarket.com", 137, wallet ); const safeAddress = "0x1234567890123456789012345678901234567890"; try { const isDeployed = await client.getDeployed(safeAddress); if (isDeployed) { console.log("Safe is deployed at:", safeAddress); } else { console.log("Safe not yet deployed at:", safeAddress); console.log("Call client.deploy() to deploy the Safe"); } } catch (error) { console.error("Error checking deployment status:", error); } ``` -------------------------------- ### List All Transactions using TypeScript Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Retrieves a list of all transactions associated with the authenticated account. It requires the RelayClient to be initialized with credentials and configuration. The output is an array of transaction objects, each containing details like transaction ID, hash, state, and timestamps. ```typescript import { RelayClient } from "@polymarket/builder-relayer-client"; import { BuilderApiKeyCreds, BuilderConfig } from "@polymarket/builder-signing-sdk"; const builderCreds: BuilderApiKeyCreds = { key: process.env.BUILDER_API_KEY, secret: process.env.BUILDER_SECRET, passphrase: process.env.BUILDER_PASS_PHRASE, }; const builderConfig = new BuilderConfig({ localBuilderCreds: builderCreds }); const client = new RelayClient( "https://relayer.polymarket.com", 137, wallet, builderConfig ); try { const transactions = await client.getTransactions(); console.log(`Found ${transactions.length} transactions`); transactions.forEach((txn, index) => { console.log(`\nTransaction ${index + 1}:`); console.log(" ID:", txn.transactionID); console.log(" Hash:", txn.transactionHash); console.log(" State:", txn.state); console.log(" From:", txn.from); console.log(" To:", txn.to); console.log(" Metadata:", txn.metadata); console.log(" Created:", txn.createdAt); }); } catch (error) { console.error("Error fetching transactions:", error); } ``` -------------------------------- ### Redeem Positions using NegRisk Adapter with Builder Relayer Client Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Prepares and executes a transaction to redeem positions using the NegRisk adapter. This function is compatible with both SAFE and PROXY transaction types. It requires the adapter address, condition ID, and an array of redeem amounts (yes and no tokens) as input. ```typescript import { encodeFunctionData, prepareEncodeFunctionData } from "viem"; import { Transaction, RelayerTxType } from "@polymarket/builder-relayer-client"; const nrAdapterRedeemAbi = [ { "inputs": [ {"internalType": "bytes32", "name": "_conditionId", "type": "bytes32"}, {"internalType": "uint256[]", "name": "_amounts", "type": "uint256[]"} ], "name": "redeemPositions", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ]; const nrAdapter = prepareEncodeFunctionData({ abi: nrAdapterRedeemAbi, functionName: "redeemPositions", }); function createNrAdapterRedeemTransaction( adapterAddress: string, conditionId: string, redeemAmounts: bigint[] // [yesAmount, noAmount] ): Transaction { const calldata = encodeFunctionData({ ...nrAdapter, args: [conditionId, redeemAmounts] }); return { to: adapterAddress, data: calldata, value: "0" }; } // Initialize client with SAFE transaction type (default) const safeClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig, RelayerTxType.PROXY); // Execute the redeem - works with both SAFE and PROXY const negRiskAdapter = "0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296"; const conditionId = "0x..."; // Your condition ID const redeemAmounts = [BigInt(111000000), BigInt(0)]; // [yes tokens, no tokens] const redeemTx = createNrAdapterRedeemTransaction(negRiskAdapter, conditionId, redeemAmounts); // Using SAFE client const safeResponse = await safeClient.execute([redeemTx], "redeem positions"); const safeResult = await safeResponse.wait(); console.log("Safe redeem completed:", safeResult.transactionHash); // Using PROXY client const proxyResponse = await proxyClient.execute([redeemTx], "redeem positions"); const proxyResult = await proxyResponse.wait(); console.log("Proxy redeem completed:", proxyResult.transactionHash); ``` -------------------------------- ### Execute Transaction Batch with Polymarket RelayClient (TypeScript) Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Executes one or more transactions through the Polymarket relayer, leveraging automatic batching and state tracking. This function prepares an ERC20 approval transaction and then submits it for relaying. It uses viem for encoding transaction data and expects the RelayClient instance to be initialized. ```typescript import { encodeFunctionData, prepareEncodeFunctionData, maxUint256 } from "viem"; import { Transaction } from "@polymarket/builder-relayer-client"; // Define ERC20 approve function const erc20Abi = [ { "constant": false, "inputs": [ {"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"} ], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "type": "function" } ]; const erc20 = prepareEncodeFunctionData({ abi: erc20Abi, functionName: "approve", }); // Create approval transaction function createApprovalTransaction(tokenAddress: string, spenderAddress: string): Transaction { const calldata = encodeFunctionData({ ...erc20, args: [spenderAddress, maxUint256] }); return { to: tokenAddress, data: calldata, value: "0" }; } // Execute transaction const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; const ctfAddress = "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"; const approvalTx = createApprovalTransaction(usdcAddress, ctfAddress); try { const response = await client.execute([approvalTx], "USDC approval on CTF"); const result = await response.wait(); if (result) { console.log("Transaction completed!"); console.log("Transaction Hash:", result.transactionHash); console.log("Transaction ID:", result.transactionID); console.log("State:", result.state); } else { console.error("Transaction failed"); } } catch (error) { console.error("Execution error:", error); } ``` -------------------------------- ### Redeem NegRisk Adapter Positions with Viem Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Redeems positions through the NegRisk Adapter for negative risk markets using Viem. It requires the adapter's address, the condition ID, and an array of amounts to redeem for each outcome. This function generates a Transaction object for execution. ```typescript import { encodeFunctionData, prepareEncodeFunctionData } from "viem"; import { Transaction } from "@polymarket/builder-relayer-client"; const nrAdapterRedeemAbi = [ { "inputs": [ {"internalType": "bytes32", "name": "_conditionId", "type": "bytes32"}, {"internalType": "uint256[]", "name": "_amounts", "type": "uint256[]"} ], "name": "redeemPositions", "outputs": [], "type": "function" } ]; const nrAdapter = prepareEncodeFunctionData({ abi: nrAdapterRedeemAbi, functionName: "redeemPositions", }); function createNrAdapterRedeemTransaction( adapterAddress: string, conditionId: string, redeemAmounts: bigint[] // [yesAmount, noAmount] ): Transaction { const calldata = encodeFunctionData({ ...nrAdapter, args: [conditionId, redeemAmounts] }); return { to: adapterAddress, data: calldata, value: "0" }; } const negRiskAdapter = "0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296"; const conditionId = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"; const redeemAmounts = [BigInt(111000000), BigInt(0)]; // [111 yes tokens, 0 no tokens] try { const redeemTx = createNrAdapterRedeemTransaction( negRiskAdapter, conditionId, redeemAmounts ); const response = await client.execute([redeemTx], "redeem NegRisk positions"); const result = await response.wait(); if (result) { console.log("NegRisk positions redeemed successfully!"); console.log("Transaction Hash:", result.transactionHash); console.log("Yes tokens redeemed:", redeemAmounts[0].toString()); console.log("No tokens redeemed:", redeemAmounts[1].toString()); } else { console.error("NegRisk redemption failed"); } } catch (error) { console.error("NegRisk redemption error:", error); } ``` -------------------------------- ### Redeem NegRisk Adapter Positions Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Redeem positions through the NegRisk Adapter for negative risk markets with specified amounts per outcome. ```APIDOC ## Redeem NegRisk Adapter Positions ### Description Redeem positions through the NegRisk Adapter for negative risk markets with specified amounts per outcome. ### Method (Implicitly POST via `client.execute`) ### Endpoint (Not explicitly defined, but interacts with the relayer client) ### Parameters #### Request Body (Implicit in `client.execute`) - **redeemTx** (Transaction) - The transaction object created by `createNrAdapterRedeemTransaction`. ### Request Example ```typescript // Assuming 'client' is an initialized RelayClient instance const negRiskAdapter = "0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296"; const conditionId = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"; const redeemAmounts = [BigInt(111000000), BigInt(0)]; // [111 yes tokens, 0 no tokens] const redeemTx = createNrAdapterRedeemTransaction( negRiskAdapter, conditionId, redeemAmounts ); const response = await client.execute([redeemTx], "redeem NegRisk positions"); const result = await response.wait(); if (result) { console.log("NegRisk positions redeemed successfully!"); console.log("Transaction Hash:", result.transactionHash); console.log("Yes tokens redeemed:", redeemAmounts[0].toString()); console.log("No tokens redeemed:", redeemAmounts[1].toString()); } else { console.error("NegRisk redemption failed"); } ``` ### Response #### Success Response - **result** (object | null) - An object containing transaction details if successful, otherwise null. - **transactionHash** (string) - The hash of the successfully executed transaction. #### Response Example ```json { "transactionHash": "0xabc123..." } ``` ``` -------------------------------- ### Redeem Positions using CTF Adapter with Builder Relayer Client Source: https://github.com/polymarket/builder-relayer-client/blob/main/README.md Prepares and executes a transaction to redeem positions using the CTF (ConditionalTokensFramework) adapter. This function supports both SAFE and PROXY transaction types. It requires the CTF contract address, collateral token address, and condition ID as input. ```typescript import { encodeFunctionData, prepareEncodeFunctionData, zeroHash } from "viem"; import { Transaction, RelayerTxType } from "@polymarket/builder-relayer-client"; const ctfRedeemAbi = [ { "constant": false, "inputs": [ {"name": "collateralToken", "type": "address"}, {"name": "parentCollectionId", "type": "bytes32"}, {"name": "conditionId", "type": "bytes32"}, {"name": "indexSets", "type": "uint256[]"} ], "name": "redeemPositions", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" } ]; const ctf = prepareEncodeFunctionData({ abi: ctfRedeemAbi, functionName: "redeemPositions", }); function createCtfRedeemTransaction( ctfAddress: string, collateralToken: string, conditionId: string ): Transaction { const calldata = encodeFunctionData({ ...ctf, args: [collateralToken, zeroHash, conditionId, [1, 2]] }); return { to: ctfAddress, data: calldata, value: "0" }; } // Initialize client with SAFE transaction type (default) const safeClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig); // Or initialize with PROXY transaction type const proxyClient = new RelayClient(relayerUrl, chainId, wallet, builderConfig, RelayerTxType.PROXY); // Execute the redeem - works with both SAFE and PROXY const ctfAddress = "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"; const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; const conditionId = "0x..."; // Your condition ID const redeemTx = createCtfRedeemTransaction(ctfAddress, usdcAddress, conditionId); // Using SAFE client const safeResponse = await safeClient.execute([redeemTx], "redeem positions"); const safeResult = await safeResponse.wait(); console.log("Safe redeem completed:", safeResult.transactionHash); // Using PROXY client const proxyResponse = await proxyClient.execute([redeemTx], "redeem positions"); const proxyResult = await proxyResponse.wait(); console.log("Proxy redeem completed:", proxyResult.transactionHash); ``` -------------------------------- ### Retrieve Transaction Status with Polymarket Builder Relayer Client (TypeScript) Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Fetches transaction details using a provided transaction ID. This allows checking the current status and execution details of a specific transaction. The output includes various fields like transaction hash, sender, receiver, state, and timestamps. ```typescript import { RelayClient } from "@polymarket/builder-relayer-client"; const client = new RelayClient( "https://relayer.polymarket.com", 137 ); const transactionId = "0191580c-6472-7266-beda-4deaebe46705"; try { const transactions = await client.getTransaction(transactionId); if (transactions.length > 0) { const txn = transactions[0]; console.log("Transaction Details:"); console.log(" ID:", txn.transactionID); console.log(" Hash:", txn.transactionHash); console.log(" From:", txn.from); console.log(" To:", txn.to); console.log(" State:", txn.state); console.log(" Proxy Address:", txn.proxyAddress); console.log(" Nonce:", txn.nonce); console.log(" Metadata:", txn.metadata); console.log(" Created At:", txn.createdAt); console.log(" Updated At:", txn.updatedAt); } else { console.log("Transaction not found"); } } catch (error) { console.error("Error fetching transaction:", error); } ``` -------------------------------- ### Redeem CTF Positions with Viem Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Redeems positions from the ConditionalTokensFramework after market resolution using Viem for encoding transaction data. It requires the CTF contract address, collateral token address, and condition ID. The function returns a Transaction object ready for execution. ```typescript import { encodeFunctionData, prepareEncodeFunctionData, zeroHash } from "viem"; import { Transaction } from "@polymarket/builder-relayer-client"; const ctfRedeemAbi = [ { "constant": false, "inputs": [ {"name": "collateralToken", "type": "address"}, {"name": "parentCollectionId", "type": "bytes32"}, {"name": "conditionId", "type": "bytes32"}, {"name": "indexSets", "type": "uint256[]"} ], "name": "redeemPositions", "outputs": [], "type": "function" } ]; const ctf = prepareEncodeFunctionData({ abi: ctfRedeemAbi, functionName: "redeemPositions", }); function createCtfRedeemTransaction( ctfAddress: string, collateralToken: string, conditionId: string ): Transaction { const calldata = encodeFunctionData({ ...ctf, args: [collateralToken, zeroHash, conditionId, [1, 2]] }); return { to: ctfAddress, data: calldata, value: "0" }; } const ctfAddress = "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"; const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; const conditionId = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"; try { const redeemTx = createCtfRedeemTransaction(ctfAddress, usdcAddress, conditionId); const response = await client.execute([redeemTx], "redeem CTF positions"); const result = await response.wait(); if (result) { console.log("Positions redeemed successfully!"); console.log("Transaction Hash:", result.transactionHash); } else { console.error("Redemption failed"); } } catch (error) { console.error("Redemption error:", error); } ``` -------------------------------- ### Redeem CTF Positions Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Redeem positions from the ConditionalTokensFramework after market resolution using the provided parameters. ```APIDOC ## Redeem CTF Positions ### Description Redeem positions from the ConditionalTokensFramework after market resolution. ### Method (Implicitly POST via `client.execute`) ### Endpoint (Not explicitly defined, but interacts with the relayer client) ### Parameters #### Request Body (Implicit in `client.execute`) - **redeemTx** (Transaction) - The transaction object created by `createCtfRedeemTransaction`. ### Request Example ```typescript // Assuming 'client' is an initialized RelayClient instance const ctfAddress = "0x4d97dcd97ec945f40cf65f87097ace5ea0476045"; const usdcAddress = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; const conditionId = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"; const redeemTx = createCtfRedeemTransaction(ctfAddress, usdcAddress, conditionId); const response = await client.execute([redeemTx], "redeem CTF positions"); const result = await response.wait(); if (result) { console.log("Positions redeemed successfully!"); console.log("Transaction Hash:", result.transactionHash); } else { console.error("Redemption failed"); } ``` ### Response #### Success Response - **result** (object | null) - An object containing transaction details if successful, otherwise null. - **transactionHash** (string) - The hash of the successfully executed transaction. #### Response Example ```json { "transactionHash": "0xabc123..." } ``` ``` -------------------------------- ### Poll Transaction Until Completion with Polymarket Builder Relayer Client (TypeScript) Source: https://context7.com/polymarket/builder-relayer-client/llms.txt Continuously polls for a transaction's status until it reaches a specified state or a timeout occurs. This function is useful for waiting for transactions to be confirmed or mined. It allows configuration of target states, a failure state, maximum poll count, and polling interval. ```typescript import { RelayClient } from "@polymarket/builder-relayer-client"; import { RelayerTransactionState } from "@polymarket/builder-relayer-client"; const client = new RelayClient( "https://relayer.polymarket.com", 137 ); const transactionId = "0190e61a-bb93-7c3f-88e2-e29e1c569fb1"; // Poll for confirmed state const confirmationStates = [ RelayerTransactionState.STATE_CONFIRMED, RelayerTransactionState.STATE_MINED ]; try { const result = await client.pollUntilState( transactionId, confirmationStates, RelayerTransactionState.STATE_FAILED, // Fail state 50, // Max 50 polls 3000 // Poll every 3 seconds ); if (result) { console.log("Transaction reached desired state!"); console.log("Final State:", result.state); console.log("Transaction Hash:", result.transactionHash); console.log("Block confirmed at:", result.updatedAt); } else { console.log("Transaction failed or timed out"); } } catch (error) { console.error("Polling error:", error); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.