### Installing Shyft JS SDK via npm Source: https://github.com/shyft-to/js/blob/main/README.md This snippet provides the command-line instruction to install the Shyft JS SDK using the npm package manager. It is the first step required to integrate the SDK into any JavaScript or TypeScript project. ```bash npm install @shyft-to/js ``` -------------------------------- ### Fetching Wallet Balance with Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This example illustrates how to initialize the Shyft SDK with an API key and network, then asynchronously fetch the SOL balance for a specified wallet address using the wallet.getBalance method. The result is logged to the console, demonstrating a basic interaction with the Wallet API. ```typescript const shyft = new ShyftSdk({ apiKey: 'YOUR_API_KEY', network: Network.Devnet }); (async () => { const balance = await shyft.wallet.getBalance({ wallet: 'WALLET_ADDRESS' }); console.log(balance); })(); ``` -------------------------------- ### Fetching Assets by Collection with Shyft RPC API (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This example demonstrates how to use the Shyft SDK to retrieve assets belonging to a specific collection using the RPC `getAssetsByGroup` method. It initializes the SDK with an API key and network, then queries for assets, sorting them by creation date in ascending order, and logs the retrieved items. ```typescript import { ShyftSdk, Network } from '@shyft-to/js'; const shyft = new ShyftSdk({ apiKey: 'YOUR_API_KEY', network: Network.Mainnet }); (async () => { const response = await shyft.rpc.getAssetsByGroup({ groupKey: 'collection', groupValue: 'BxWpbnau1LfemNAoXuAe9Pbft59yz2egTxaMWtncGRfN', sortBy: { sortBy: 'created', sortDirection: 'asc' }, page: 1, limit: 1000 }); const assets = response.items; console.log(assets); })(); ``` -------------------------------- ### Minting a Compressed NFT using Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This example illustrates how to mint a compressed NFT (cNFT) using the `shyft.nft.compressed.mint` method. It requires the creator's wallet, a merkle tree address, a metadata URI, a collection address, and the receiver's wallet address. The response contains details of the minted cNFT. ```TypeScript const mintResponse = await shyft.nft.compressed.mint({ creatorWallet: '2fmz8SuNVyxEP6QwKQs6LNaT2ATszySPEJdhUDesxktc', merkleTree: 'DwoJS9LVDVL55Qa2TwvGG8MqNB5He4JtbnrHQ7JCrkcP', metadataUri: 'https://nftstorage.link/ipfs/bafkreigjxlfjhnpync5qmgv73yi4lqz4e65axwgpgqumvbopgvdrkwjpcm', collectionAddress: 'DgXdP7xA31HEviRKw6pk9Xj342dEWy8HFn1yjcsXZ9M9', receiver: '5KW2twHzRsAaiLeEx4zYNV35CV2hRrZGw7NYbwMfL4a2', }); console.log(mintResponse); ``` -------------------------------- ### Fetching Active Marketplace Listings with Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This example demonstrates how to retrieve active NFT listings from a specified marketplace using the `shyft.marketplace.listing.active()` method. It allows for filtering and pagination with parameters like `network`, `marketplaceAddress`, `sortBy`, `sortOrder`, `page`, and `size`. The function returns an array of active listings, which is then logged to the console. ```typescript const activeListings = await shyft.marketplace.listing.active({ network: Network.Mainnet, marketplaceAddress: 'AxrRwpzk4T6BsWhttPwVCmfeEMbfbasv1QxVc5JhUfvB', sortBy: 'price', sortOrder: 'desc', page: 1, size: 2, }); console.log(activeListings); ``` -------------------------------- ### Fetching an NFT by Mint Address using Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates how to initialize the Shyft SDK and use the `getNftByMint` method to retrieve on-chain and off-chain data for a specific NFT using its mint address. It requires an API key and specifies the network for SDK initialization. ```TypeScript const shyft = new ShyftSdk({ apiKey: 'YOUR_API_KEY', network: Network.Devnet }); (async () => { const nft = await shyft.nft.getNftByMint({ mint: 'NFT_MINT' }); console.log(nft); })(); ``` -------------------------------- ### Creating a Solana Marketplace with Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This code illustrates how to create a new on-chain NFT marketplace using the `shyft.marketplace.create()` function. It requires a `creatorWallet` address as a parameter, which specifies the wallet responsible for the marketplace. The method returns an `encoded_transaction` which can then be signed and sent to the Solana blockchain to finalize the marketplace creation. ```typescript const { encoded_transaction } = await shyft.marketplace.create({ creatorWallet: '2fmz8SuNVyxEP6QwKQs6LNaT2ATszySPEJdhUDesxktc', }); console.log(encoded_transaction); ``` -------------------------------- ### Fetching Fungible Token Information using Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates how to initialize the Shyft SDK and use the `shyft.token.getInfo` method to retrieve detailed information about an already launched fungible token. It requires the network and the token's address as parameters for the `getInfo` call. ```TypeScript const shyft = new ShyftSdk({ apiKey: 'YOUR_API_KEY', network: Network.Devnet }); (async () => { const token = await shyft.token.getInfo({ network: Network.Mainnet, tokenAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', }); console.log(token); })(); ``` -------------------------------- ### Importing Shyft SDK in TypeScript Projects Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates the ES module import syntax for integrating the Shyft SDK into TypeScript applications. It imports the main ShyftSdk class and the Network enum, which are essential for SDK initialization and network configuration. ```typescript import { ShyftSdk, Network } = '@shyft-to/js'; ``` -------------------------------- ### Listing an NFT on a Shyft Marketplace (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet shows how to list an NFT for sale on an existing marketplace using the `shyft.marketplace.listing.list()` method. It takes parameters such as `marketplaceAddress`, `nftAddress`, `price`, `sellerWallet`, and an optional `isGasLess` flag to define the listing terms. The function returns an `encoded_transaction` that needs to be signed and submitted to complete the listing operation. ```typescript const { encoded_transaction } = await shyft.marketplace.listing.list({ marketplaceAddress: 'dKtXyGgDGCyXiWtj9mbXUXk7ww996Uyc46CVt3ukJwV', nftAddress: '7Ros6azxoYakj3agxZetDwTWySftQeYXRXAKYWgXTWvw', price: 50, sellerWallet: '8hDQqsj9o2LwMk2FPBs7Rz5jPuzqKpRvkeeo6hMJm5Cv', isGasLess: true, }); console.log(encoded_transaction); ``` -------------------------------- ### Creating NFT Metadata using Shyft Storage API (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This code illustrates how to create an NFT metadata JSON file on decentralized storage (IPFS) using the Shyft SDK's storage API. It specifies essential metadata fields like creator, image URI, name, symbol, description, attributes, and seller fee basis points, then logs the resulting content URI. ```typescript const { uri } = await shyft.storage.createMetadata({ creator: '2fmz8SuNVyxEP6QwKQs6LNaT2ATszySPEJdhUDesxktc', image: 'https://nftstorage.link/ipfs/bafkreiajrjd7xozubfr7qk6xdktlo3k66jg6jkeamgjugd2p3w5w2pifve', name: 'Nirvana', symbol: 'NVN', description: 'This is a test NFT', attributes: [ { trait_type: 'anger', value: 0 }, { trait_type: 'calmness', value: 100 } ], sellerFeeBasisPoints: 500 }); console.log(uri); ``` -------------------------------- ### Fetching Transaction History with Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates how to fetch transaction history for a specific account on the Solana Devnet using the Shyft SDK. It enables raw transaction data for detailed inspection and logs the full response to the console. ```typescript const transactions = await shyft.transaction.history({ network: Network.Devnet, account: 'Apeng15Pm8EjpAcaAXpNUxZjS2jMmGqikfs281Fz9hNj', enableRaw: true, }); console.dir(transactions, { depth: null }); ``` -------------------------------- ### Reading Candy Machine Mints in Shyft SDK (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates how to retrieve all NFT addresses minted by a specific Candy Machine using the `shyft.candyMachine.readMints()` method. It initializes the Shyft SDK with an API key and network, then calls the method with the Candy Machine address and version, logging the resulting list of mints. This allows developers to track all NFTs originating from a particular Candy Machine. ```typescript const shyft = new ShyftSdk({ apiKey: 'YOUR_API_KEY', network: Network.Devnet }); (async () => { const mints = await shyftcandyMachine.readMints({ address: 'H2oYLkXdkX38eQ6VTqs26KAWAvEpYEiCtLt4knEUJxpu', version: CandyMachineProgram.V2, }); console.log(mints); })(); ``` -------------------------------- ### Signing and Sending Transactions with Private Keys (TypeScript) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet demonstrates how to sign and send a Solana transaction using the `signAndSendTransactionWithPrivateKeys` function from `@shyft-to/js`. It requires the network, an encoded transaction string (obtained from Shyft API), and an array of private keys. The function returns the transaction signature upon success. ```typescript import { signAndSendTransactionWithPrivateKeys, Network } from '@shyft-to/js'; const network = Network.Devnet; const privateKeys = ['PRIVATE_KEY_ONE', 'PRIVATE_KEY_TWO']; // Get using Shyft API const encodedTransaction = '5eG1aSjNoPmScw84G1d7f9n2fgmWabtQEgRjTUXvpTrRH1qduEMwUvUFYiS8px22JNedkWFTUWj9PrRyq1MyessunKC8Mjyq3hH5WZkM15D3gsooH8hsFegyYRBmccLBTEnPph6fExEySkJwsfH6oGC62VmDDCpWyPHZLYv52e4qtUb1TBE6SgXE6FX3TFqrX5HApSkb9ZaCSz21FyyEbXtrmMxBQE1CR7BTyadWL1Vy9SLfo9tnsVpHHDHthFRr'; (async () => { try { const txnSignature = await signAndSendTransactionWithPrivateKeys( network, encodedTransaction, privateKeys ); console.log(txnSignature); } catch (error) { throw new Error(error); } })(); ``` -------------------------------- ### Importing Shyft SDK in JavaScript (CommonJS) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet shows the CommonJS require syntax for importing the Shyft SDK components in JavaScript environments. It allows developers to access the ShyftSdk class and Network enum, typically used in Node.js applications. ```javascript const { ShyftSdk, Network } = require('@shyft-to/js'); ``` -------------------------------- ### Signing and Sending Transactions with Wallet Adapter (TSX) Source: https://github.com/shyft-to/js/blob/main/README.md This snippet illustrates how to sign and send a Solana transaction using the `signAndSendTransaction` function from `@shyft-to/js` in a React/TSX environment. It leverages `@solana/wallet-adapter-react` to obtain the connection and wallet objects, which are then passed along with the encoded transaction. This method is suitable for frontend applications where the user's wallet handles the signing. ```tsx import { useConnection, useWallet } from '@solana/wallet-adapter-react'; import { signAndSendTransaction, Network, ShyftWallet } from '@shyft-to/js'; const { connection } = useConnection(); const wallet = useWallet(); // Get using Shyft API const encodedTransaction = '5eG1aSjNoPmScw84G1d7f9n2fgmWabtQEgRjTUXvpTrRH1qduEMwUvUFYiS8px22JNedkWFTUWj9PrRyq1MyessunKC8Mjyq3hH5WZkM15D3gsooH8hsFegyYRBmccLBTEnPph6fExEySkJwsfH6oGC62VmDDCpWyPHZLYv52e4qtUb1TBE6SgXE6FX3TFqrX5HApSkb9ZaCSz21FyyEbXtrmMxBQE1CR7BTyadWL1Vy9SLfo9tnsVpHHDHthFRr'; (async () => { try { const txnSignature = await signAndSendTransaction( connection, encodedTransaction, wallet ); console.log(txnSignature); } catch (error) { throw new Error(error); } })(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.