### Install HandCash Connect SDK Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Install the HandCash Connect SDK using npm. This command is required before using the SDK in your Node.js project. ```bash npm i @handcash/handcash-connect ``` -------------------------------- ### Get User Spendable Balance Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Fetch the amount of money a user can spend. This takes into account any daily spending limits set by the user. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: '', appSecret: '', }); const account = handCashConnect.getAccountFromAuthToken(token); const spendableBalance = await account.wallet.getSpendableBalance(); console.log(spendableBalance); ``` -------------------------------- ### Get Deposit Address Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Retrieve a deposit address for your HandCash wallet using the `getDepositAddress` method. ```javascript account.wallet.getDepositAddress() ``` -------------------------------- ### Get total balance Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Retrieves the user's total balance from the wallet account. This method is available on the `account.wallet` object. ```javascript account.wallet.getTotalBalance() ``` -------------------------------- ### Get User Inventory Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Retrieve a list of items from the user's inventory. You can specify filters like 'from' and 'to' to paginate the results. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: '', appSecret: '', }); const account = handCashConnect.getAccountFromAuthToken(token); const items = await account.items.getItemsInventory({ from: 0, to: 50 }); console.log(items); ``` -------------------------------- ### Get Item by Origin Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Retrieve an item using its origin identifier. This method is available from version 0.8.1 onwards. ```javascript account.items.getItemByOrigin('origin') ``` -------------------------------- ### Get Account from Auth Token Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Create an account object using an authentication token obtained after user authorization. This object is used to access user-specific data and actions. ```typescript const account = handCashConnect.getAccountFromAuthToken(authToken); ``` -------------------------------- ### Get change spend limits URL Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Provides a method to obtain the URL for changing spend limits. This is useful for integrating with HandCash Connect's RUN features. ```javascript handCashConnect.getChangeSpendLimitsUrl() ``` -------------------------------- ### Get Redirection URL for User Authorization Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Obtain the URL to redirect users to HandCash for authorization. This URL is used to initiate the user authorization process. ```typescript const redirectionUrl = handCashConnect.getRedirectionUrl(); ``` -------------------------------- ### Get User Profile Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Retrieve the current user's public profile information. Ensure the HandCashConnect instance is initialized and an account object is obtained from an auth token. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: '', appSecret: '', }); const account = handCashConnect.getAccountFromAuthToken(token); const { publicProfile } = await account.profile.getCurrentProfile(); console.log(publicProfile); ``` -------------------------------- ### Create a Collection Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Create a new collection to group your digital items. This requires a name, description, and media details for the collection's image. Copy the returned collectionId for future use. ```typescript const creationOrder = await handCashMinter.createCollectionOrder({ name: 'My first collection', description: 'This is my first collection. Do not judge me.', mediaDetails: { image: { url: 'https://res.cloudinary.com/handcash-iae/image/upload/v1685141160/round-handcash-logo_cj47fp_xnteyo_oy3nbd.png', contentType: 'image/png' } } }); const items = await handCashMinter.getOrderItems(creationOrder.id); console.log(`Collection Created, collectionId: ${items[0].id}`); ``` -------------------------------- ### Initialize HandCash Connect SDK Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Instantiate the HandCashConnect object with your application's appId and appSecret. This is the first step to interacting with the SDK. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: 'your-app-id', appSecret: 'your-app-secret', }); ``` -------------------------------- ### Create Item with Actions Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Define item actions when creating a new item. Each action includes a name, description, and a URL for redirection. This snippet demonstrates creating a 'Mystery box' with an 'Open' action. ```typescript const creationOrder = await handCashMinter.createItemsOrder({ collectionId, items: [ { user: "612cba70e108780b4f6817ad", name: "Mystery box", rarity: "Mythic", mediaDetails: { image: { url: "https://res.cloudinary.com/handcash-iae/image/upload/v1702398977/items/jyn2a2yqyepqhqi9p661.webp", imageHighResUrl: "https://res.cloudinary.com/handcash-iae/image/upload/v1702398977/items/jyn2a2yqyepqhqi9p661.png", contentType: "image/png" } }, actions: [ { name: "Open", description: "Redeem this box for 10x random items.", url: "https://mygame.com/actions/open" } ], quantity: 1, } ] }); ``` -------------------------------- ### Extend HandCashOwner with alias Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Shows how to use the `nextOwner` method on `HandCashOwner` with an optional alias parameter. ```javascript HandCashOwner.nextOwner(alias) ``` -------------------------------- ### Create Account with Named Parameters Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Create a new HandCash account using the `createAccount` method with named parameters for clarity. ```javascript handCashConnect.createAccount({...}) ``` -------------------------------- ### Create HandCash Account Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/createAccount.md This snippet demonstrates the full process of creating a new HandCash account, including requesting an email verification code, generating an authentication key pair, verifying the code, and finally creating the account. Store the generated private key securely for future access. ```typescript const handCashConnect = new HandCashConnect({ appId: handcashAppId, appSecret: handcashAppSecret }); // 1. Request an email verification code const email = 'app.review@handcash.io'; const requestId = await handCashConnect.requestEmailCode(email); // 2. Generate an authentication key pair const keyPair = handCashConnect.generateAuthenticationKeyPair(); // 3. Verify the email code const verificationCode = '12345678'; await handCashConnect.verifyEmailCode(requestId, verificationCode, keyPair.publicKey); // 4. Create the account await handCashConnect.createAccount({ accessPublicKey: keyPair.publicKey, email, }); // Use the SDK as usual const cloudAccount = handCashConnect.getAccountFromAuthToken(keyPair.privateKey); const profileFromAuthToken = await cloudAccount.profile.getCurrentProfile(); ``` -------------------------------- ### Initialize HandCash Items SDK Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Initialize the HandCashMinter with your application credentials. This is the first step before performing any item management operations. ```typescript import { HandCashMinter } from '@handcash/handcash-connect'; const handCashMinter = HandCashMinter.fromAppCredentials({ appId: '', appSecret: '', }); ``` -------------------------------- ### Burn and Create Items Order Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Efficiently burn and create items in a single transaction using the `burnAndCreateItemsOrder` method. ```javascript minter.burnAndCreateItemsOrder({...}) ``` -------------------------------- ### Add tags to payment items Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Demonstrates how to add tags to payment items when making a payment. Ensure the `PaymentParameters` interface is correctly typed. ```javascript wallet.pay({ payments: [{ destination: 'satoshi', tags: ['tag1', 'tag2'], currencyCode: 'USD', sendAmount: 0.05}] }); ``` -------------------------------- ### Create Items within a Collection Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Mint new digital items, referencing a previously created collectionId. Each item can have a user, name, rarity, attributes, media details, and quantity. The mediaDetails include URLs for the item's image representation. ```typescript const creationOrder = await handCashMinter.createItemsOrder({ collectionId: 'replace-with-your-collection-id', items: [ { user: '6213a44bf2936f711c8d19d3', name: "My first item", rarity: "Mythic", attributes: [ { name: "Strenth", value: 10, displayType: "number" }, { name: "Speed", value: 9, displayType: "number" }, { name: "Skin", value: "Purple", displayType: "string" }, ], mediaDetails: { image: { url: "https://res.cloudinary.com/handcash-iae/image/upload/v1702398977/items/jyn2qqyqyepqhqi9p661.webp", imageHighResUrl: "https://res.cloudinary.com/handcash-iae/image/upload/v1697465892/items/zq0lupxoj8id1uedgz2h.png", contentType: "image/webp" } }, quantity: 3 }, ] }); const items = await handCashMinter.getOrderItems(creationOrder.id); console.log('Items created', items); ``` -------------------------------- ### Create Item Order with Custom Reference Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Create an item order and include a custom reference for tracking. This feature was added in version 0.8.1. ```javascript minter.createItemsOrder({ uid: 'custom', ...}) ``` -------------------------------- ### Transfer Money Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Initiate a payment from the user's wallet to another HandCash user. Specify the description, currency, amount, and destination. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: '', appSecret: '', }); const account = handCashConnect.getAccountFromAuthToken(token); const paymentParameters = { description: "Hold my beer!🍺", payments: [ { currencyCode: 'USD', sendAmount: 0.25, destination: 'nosetwo' }, ] }; const paymentResult = await account.wallet.pay(paymentParameters); console.log(paymentResult); ``` -------------------------------- ### Lock and Unlock Items Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/CHANGELOG.md Use these methods to manage item locking status. `getLockedItems` retrieves the current locked items. ```javascript account.items.lockItems(origin) ``` ```javascript account.items.unlockItems(origin) ``` ```javascript account.items.getLockedItems({...}) ``` -------------------------------- ### Item Sold Event Payload Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/webhooksMigration.md This JSON payload represents the 'item_listing_payment_completed' event, detailing the transaction, item, and transfer information when an item is sold. ```json { "event": "item_listing_payment_completed", "applicationId": "817f191e330a19629de750eb", "apiVersion": "1.0", "created": "2024-02-01T17:05:58.135Z", "data": { "transactionRecord": { "transactionId": "2582c8e5364b151343bbcea576a7411b052e227288f251d0bb40028314af59ea", "note": "Fairy of the Moonlight", "type": "receive", "time": 1706807157, "satoshiFees": 0, "satoshiAmount": 5000, "fiatExchangeRate": 330, "fiatCurrencyCode": "USD", "participants": [ { "type": "user", "id": "65bbcf6bcf7a2c32e3d8a7c0", "alias": "user_tss03", "displayName": "User Tss 03", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": { "rarityLabel": "Mythic", "color": "#000000", "origin": "someorigin_0" }, "responseNote": "", "tags": [] } ], "attachments": [] }, "items": [ { "to": { "type": "user", "id": "65bbcf6bcf7a2c32e3d8a7c0", "alias": "user_tss03", "displayName": "User Tss 03", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "from": { "type": "user", "id": "65bbcf6bcf7a2c32e3d8bf", "alias": "user_tss02", "displayName": "User Tss 02", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1", "name": "Fairy of the Moonlight", "imageUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1679911515/dashboard/hqw2p8tps1hbt3yxle3t.jpg", "id": "65bbcf74cf7a2c32e3d8aa5a", "collection": { "id": "65bbcf6bcf7a2c32e3d8a7ee" }, "user": { "avatarMetadata": {} }, "app": { "id": "817f191e330a19629de750eb" }, "rarity": "Rare", "color": "#21bbea", "attributes": [ { "name": "edition", "value": "First", "displayType": "string" }, { "name": "generation", "value": 1, "displayType": "string" }, { "name": "championNumber", "value": 1, "displayType": "number" }, { "name": "totalQuantity", "value": 33, "displayType": "number" }, { "name": "element", "value": "Fire", "displayType": "string" }, { "name": "ability", "value": "Inferno", "displayType": "string" }, { "name": "manaCost", "value": 2, "displayType": "number" }, { "name": "health", "value": 3, "displayType": "number" }, { "name": "attack", "value": 3, "displayType": "number" }, { "name": "color", "value": "#ed5025", "displayType": "color" } ], "royalties": [], "isHandcashCreated": true, "isVerified": true, "isListing": true, "itemListing": { "id": "65bbcf75cf7a2c32e3d8aa6e", "status": "sold", "currencyCode": "BSV", "price": 0.001, "denominatedIn": "BSV", "fiatEquivalent": { "amount": 0.33, "currencyCode": "USD" }, "paymentRequestUrl": "https://pay.handcash.io/65bbcf75cf7a2c32e3d8aa74?domain=iae-app.handcash.io", "paymentRequestId": "65bbcf75cf7a2c32e3d8aa74" }, "count": 1, "isCurrentUser": false } ], "itemTransfer": { "referencedUserId": "65bbcf6bcf7a2c32e3d8bf", "transactionId": "6ec246342ddc5834f99fe5e1ee1e42788c9ccfdc480d43d6a38fb46b2f272be6", "transferItems": [ { "direction": "send", "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1", "participant": { "type": "user", "name": "user_tss03" } } ] }, "id": "65bbcf76cf7a2c32e3d8abff", "label": "marketSell", "payment": { "currencyCode": "BSV", "amount": 0.00091, "fiatEquivalent": { "currencyCode": "USD", "amount": 0.3003 } }, "createdAt": "2024-02-01T17:05:58.064Z" } } ``` -------------------------------- ### Item Sold Event Payload Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/webhooksMigration.md This JSON payload represents the 'item_listing_payment_completed' event, indicating that an item listing has been successfully paid for and sold. It includes details about the transaction, the item sold, and any associated transfers. ```json { "event": "item_listing_payment_completed", "applicationId": "817f191e330a19629de750eb", "apiVersion": "1.0", "created": "2024-02-01T16:11:55.058Z", "data": { "transactionRecord": { "transactionId": "bfc2c5f53b8684ecaaaea9ecfe2b6bea4a7435947cb412b787968ef5048e600a", "note": "Fairy of the Moonlight", "type": "receive", "time": 1706803914, "satoshiFees": 0, "satoshiAmount": 5000, "fiatExchangeRate": 330, "fiatCurrencyCode": "USD", "participants": [ { "type": "user", "id": "65bbc2c3cbc6a1bfffb4b617", "alias": "user_tss03", "displayName": "User Tss 03", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": { "rarityLabel": "Mythic", "color": "#000000", "origin": "someorigin_0" }, "responseNote": "", "amount": 0, "tags": [] } ], "attachments": [] }, "items": [ { "id": "65bbc2cacbc6a1bfffb4b8b1", "collection": { "id": "65bbc2c3cbc6a1bfffb4b645" }, "user": { "avatarMetadata": {} }, "app": { "id": "817f191e330a19629de750eb" }, "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1", "name": "Fairy of the Moonlight", "imageUrl": "https://res.cloudinary.com/hn8pdtayf/image/upload/v1679911515/dashboard/hqw2p8tps1hbt3yxle3t.jpg", "rarity": "Rare", "color": "#21bbea", "attributes": [ { "name": "edition", "value": "First", "displayType": "string" }, { "name": "generation", "value": 1, "displayType": "string" }, { "name": "championNumber", "value": 1, "displayType": "number" }, { "name": "totalQuantity", "value": 33, "displayType": "number" }, { "name": "element", "value": "Fire", "displayType": "string" }, { "name": "ability", "value": "Inferno", "displayType": "string" }, { "name": "manaCost", "value": 2, "displayType": "number" }, { "name": "health", "value": 3, "displayType": "number" }, { "name": "attack", "value": 3, "displayType": "number" }, { "name": "color", "value": "#ed5025", "displayType": "color" } ], "royalties": [], "isHandcashCreated": true, "isVerified": true, "isListing": true, "itemListing": { "id": "65bbc2cacbc6a1bfffb4b8c5", "status": "sold", "currencyCode": "BSV", "price": 0.001, "denominatedIn": "BSV", "fiatEquivalent": { "amount": 0.33, "currencyCode": "USD" }, "paymentRequestUrl": "https://pay.handcash.io/65bbc2cacbc6a1bfffb4b8cb?domain=iae-app.handcash.io", "paymentRequestId": "65bbc2cacbc6a1bfffb4b8cb" }, "count": 1, "isCurrentUser": false } ], "itemTransfer": { "referencedUserId": "65bbc2c3cbc6a1bfffb4b616", "transactionId": "6ec246342ddc5834f99fe5e1ee1e42788c9ccfdc480d43d6a38fb46b2f272be6", "transferItems": [ { "direction": "send", "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1", "participant": { "type": "user", "name": "user_tss03" } } ] } } } ``` -------------------------------- ### Transfer Items Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/README.md Transfer items from the user's inventory to another user. Requires specifying the item's origin and the destination user's identifier. ```typescript import { HandCashConnect } from '@handcash/handcash-connect'; const handCashConnect = new HandCashConnect({ appId: '', appSecret: '', }); const account = handCashConnect.getAccountFromAuthToken(token); const result = await account.items.transfer({ destinationsWithOrigins: [ { origins: ['27c02c976adbf0acb212b850ce0c0b1b796de0a646c93304f94f2dc3249cad25_33'], destination: 'TKillah', } ] }); console.log(result.transactionId); ``` -------------------------------- ### Current 'items_transferred' Webhook Payload Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/webhooksMigration.md This is the previous structure for the 'items_transferred' event payload. It uses a 'transferItems' array to detail each item transfer. ```json { "event": "items_transferred", "applicationId": "817f191e330a19629de750eb", "apiVersion": "1.0", "created": "2024-02-01T16:13:37.156Z", "data": { "itemTransfer": { "referencedUserId": "65bbc32abebf07dcacc25c9a", "transactionId": "538ae468d411330c94ffbf547e290d89ef850eda21fa2be8a125e68a5f7eb735", "transferItems": [ { "direction": "send", "origin": "1e8708cfd4cd98297c6268afce98072e12556ebbe2ac0d6bb0fb9fe8b39b0d16_0", "participant": { "type": "user", "name": "BBG" } }, { "direction": "send", "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1", "participant": { "type": "user", "name": "user_tss03" } } ] } } } ``` -------------------------------- ### New 'items_transferred' Webhook Payload Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/webhooksMigration.md This is the updated structure for the 'items_transferred' event payload. It introduces an 'items' array with more detailed 'to' and 'from' participant information. ```json { "event": "items_transferred", "applicationId": "817f191e330a19629de750eb", "apiVersion": "1.0", "created": "2024-02-01T16:21:09.749Z", "data": { "itemTransfer": { "id": "65bbc4f5ce6f7dff7db9389a", "label": "send", "items": [ { "to": { "type": "user", "id": "507e181e810c19729de860ea", "alias": "BBG", "displayName": "User Tss 01", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "from": { "type": "user", "id": "65bbc4e9ce6f7dff7db935ae", "alias": "user_tss02", "displayName": "User Tss 02", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "origin": "1e8708cfd4cd98297c6268afce98072e12556ebbe2ac0d6bb0fb9fe8b39b0d16_0" }, { "to": { "type": "user", "id": "65bbc4e9ce6f7dff7db935af", "alias": "user_tss03", "displayName": "User Tss 03", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "from": { "type": "user", "id": "65bbc4e9ce6f7dff7db935ae", "alias": "user_tss02", "displayName": "User Tss 02", "profilePictureUrl": "https://randomuser.me/api/portraits/men/14.jpg", "avatarMetadata": {}, "responseNote": "", "tags": [] }, "origin": "5780d6946e5694ac93f8360309c6037e195d4afd0e89089619c47448a7d82389_1" } ], "createdAt": "2024-02-01T16:21:09.675Z" } } } ``` -------------------------------- ### ItemTransfer Type Definition Source: https://github.com/handcash/handcash-connect-sdk-js/blob/master/docs/webhooksMigration.md Defines the structure for the `items_transferred` webhook payload. This type definition is used when the webhook is not currently in production. ```typescript type ItemTransfer = { id: string; label: string; payment?: ItemPayment; items: ItemTransferResult[]; createdAt: string; }; type ItemPayment = { transactionId: string; currencyCode: string; amount: number; fiatEquivalent: { currencyCode: string; amount: number; }; }; type ItemTransferResult = { to: TransactionParticipant; from: TransactionParticipant; origin: string; name: string; imageUrl: string; }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.