|
| 1 | +--- |
| 2 | +title: useERC1155SaleContractCheckout |
| 3 | +description: Hook para gestionar el checkout del contrato de venta ERC-1155 |
| 4 | +sidebarTitle: useERC1155SaleContractCheckout |
| 5 | +--- |
| 6 | + |
| 7 | +## Importar |
| 8 | + |
| 9 | +```tsx |
| 10 | +import { useERC1155SaleContractCheckout } from '@0xsequence/checkout' |
| 11 | +``` |
| 12 | + |
| 13 | +## Uso |
| 14 | + |
| 15 | +```tsx |
| 16 | +import { useERC1155SaleContractCheckout } from "@0xsequence/checkout" |
| 17 | +import { useAccount } from "wagmi" |
| 18 | + |
| 19 | +function App() { |
| 20 | + const { address: userAddress } = useAccount() |
| 21 | + const { openCheckoutModal } = useERC1155SaleContractCheckout({ |
| 22 | + chain: 80001, // chainId of the chain the collectible is on |
| 23 | + contractAddress: "0x0327b2f274e04d292e74a06809bcd687c63a4ba4", // address of the contract handling the minting function |
| 24 | + wallet: userAddress!, // address of the recipient |
| 25 | + collectionAddress: "0x888a322db4b8033bac3ff84412738c096f87f9d0", // address of the collection contract |
| 26 | + items: [ |
| 27 | + // array of collectibles to purchase |
| 28 | + { |
| 29 | + tokenId: "0", |
| 30 | + quantity: "1", |
| 31 | + }, |
| 32 | + ], |
| 33 | + onSuccess: (txnHash: string) => { |
| 34 | + console.log("success!", txnHash) |
| 35 | + }, |
| 36 | + onError: (error: Error) => { |
| 37 | + console.error(error) |
| 38 | + }, |
| 39 | + }) |
| 40 | + |
| 41 | + const onClick = () => { |
| 42 | + if (!userAddress) { |
| 43 | + return |
| 44 | + } |
| 45 | + openCheckoutModal() |
| 46 | + } |
| 47 | + |
| 48 | + return <button onClick={onClick}>Buy ERC-1155 collectible!</button> |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Tipo de retorno: `UseERC1155SaleContractCheckoutReturnType` |
| 53 | +El hook retorna un objeto con las siguientes propiedades: |
| 54 | + |
| 55 | +```tsx |
| 56 | +interface UseERC1155SaleContractCheckoutReturnType { |
| 57 | + openCheckoutModal: () => void |
| 58 | + closeCheckoutModal: () => void |
| 59 | + selectPaymentSettings?: SelectPaymentSettings |
| 60 | + isLoading: boolean |
| 61 | + isError: boolean |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Propiedades |
| 66 | + |
| 67 | +#### openCheckoutModal |
| 68 | +`() => void` |
| 69 | + |
| 70 | +Función para abrir el modal de checkout con la compra ERC-1155 configurada. |
| 71 | + |
| 72 | +#### closeCheckoutModal |
| 73 | +`() => void` |
| 74 | + |
| 75 | +Función para cerrar el modal de checkout. |
| 76 | + |
| 77 | +#### selectPaymentSettings |
| 78 | +`SelectPaymentSettings | undefined` |
| 79 | + |
| 80 | +```tsx |
| 81 | +export interface SelectPaymentSettings { |
| 82 | + collectibles: Collectible[] |
| 83 | + chain: number | string |
| 84 | + currencyAddress: string | Hex |
| 85 | + price: string |
| 86 | + targetContractAddress: string | Hex |
| 87 | + txData: Hex |
| 88 | + collectionAddress: string | Hex |
| 89 | + recipientAddress: string | Hex |
| 90 | + approvedSpenderAddress?: string |
| 91 | + transactionConfirmations?: number |
| 92 | + onSuccess?: (txHash: string) => void |
| 93 | + onError?: (error: Error) => void |
| 94 | + onClose?: () => void |
| 95 | + enableMainCurrencyPayment?: boolean |
| 96 | + enableSwapPayments?: boolean |
| 97 | + enableTransferFunds?: boolean |
| 98 | + creditCardProviders?: string[] |
| 99 | + copyrightText?: string |
| 100 | + customProviderCallback?: (onSuccess: (txHash: string) => void, onError: (error: Error) => void, onClose: () => void) => void |
| 101 | + supplementaryAnalyticsInfo?: SupplementaryAnalyticsInfo |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +La configuración actual de pago para el modal. |
| 106 | + |
| 107 | +#### isLoading |
| 108 | +`boolean` |
| 109 | + |
| 110 | +Indica si los datos del contrato aún se están cargando. |
| 111 | + |
| 112 | +#### isError |
| 113 | +`boolean` |
| 114 | + |
| 115 | +Indica si hubo un error al cargar los datos del contrato. |
| 116 | + |
| 117 | +## Parámetros |
| 118 | +El hook acepta un objeto de configuración con las siguientes propiedades: |
| 119 | + |
| 120 | +| Parámetro | Tipo | Descripción | |
| 121 | +| ------------------- | -------------------------------------------- | ------------------------------------------------------------ | |
| 122 | +| `chain` | `number` | ID de cadena donde está desplegado el contrato de venta | |
| 123 | +| `contractAddress` | `string` | Dirección del contrato de venta ERC-1155 | |
| 124 | +| `wallet` | `string` | Dirección del wallet que recibirá los NFTs | |
| 125 | +| `collectionAddress` | `string` | Dirección del contrato de token ERC-1155 | |
| 126 | +| `items` | `Array<{tokenId: string, quantity: string}>` | Lista de IDs de token y cantidades a comprar | |
| 127 | +| `onSuccess` | `(txnHash: string) => void` | (Opcional) Función callback cuando la transacción es exitosa | |
| 128 | +| `onError` | `(error: Error) => void` | (Opcional) Función callback cuando ocurre un error | |
| 129 | +| `onClose` | `() => void` | (Opcional) Función callback cuando se cierra el modal | |
| 130 | + |
| 131 | +## Notas |
| 132 | +Este hook simplifica el proceso de compra de tokens ERC-1155 al realizar automáticamente las siguientes acciones: |
| 133 | +- Obtener información de precios desde el contrato de venta |
| 134 | +- Determinar opciones de pago (cripto, tarjeta de crédito, etc.) |
| 135 | +- Generar los datos de transacción adecuados |
| 136 | +- Abrir y gestionar el modal de checkout |
| 137 | + |
| 138 | +## Aviso de Deprecación |
| 139 | + |
| 140 | +<Warning> |
| 141 | + El hook `useERC1155SaleContractPaymentModal` está obsoleto. Use `useERC1155SaleContractCheckout` en su lugar. |
| 142 | +</Warning> |
0 commit comments