### Install Dependencies and Run Locally Source: https://github.com/ecadlabs/taquito/blob/main/website/src/cloudflare/chatkit/README.md Navigate to the worker directory, install npm dependencies, and start the local development server. ```bash cd website/src/cloudflare/chatkit # Install dependencies npm install # Run locally npm run dev ``` -------------------------------- ### Install @taquito/wallet-connect Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-wallet-connect/README.md Install the package using npm. ```bash npm install @taquito/wallet-connect ``` -------------------------------- ### Install @taquito/http-utils Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-http-utils/README.md Install the package using npm. ```bash npm install @taquito/http-utils ``` -------------------------------- ### Install @taquito/beacon-wallet Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-beacon-wallet/README.md Install the package using npm. ```bash npm install @taquito/beacon-wallet ``` -------------------------------- ### Install and Use Compatible Node.js Version Source: https://github.com/ecadlabs/taquito/blob/main/README.md Installs and switches to a compatible Node.js version using nvm. Ensure you have nvm installed and a supported Node.js version available. ```bash nvm install nvm use ``` -------------------------------- ### Install @taquito/ledger-signer Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-ledger-signer/README.md Install the package using npm. ```bash npm install @taquito/ledger-signer ``` -------------------------------- ### Install @taquito/utils Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Install the @taquito/utils package using npm. ```bash npm i --save @taquito/utils ``` -------------------------------- ### Install @taquito/rpc Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-rpc/README.md Install the Taquito RPC package using npm. ```bash npm i --save @taquito/rpc ``` -------------------------------- ### Install and Run Taquito Website Locally Source: https://github.com/ecadlabs/taquito/blob/main/website/README.md Use these commands to install dependencies and run the Taquito website locally for development purposes. ```bash npm ci npm -w @taquito/website dev ``` -------------------------------- ### Initialize BeaconWallet and Connect to TezosToolkit Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-beacon-wallet/README.md Create a BeaconWallet instance with options and set it as the wallet provider for TezosToolkit. This example also shows how to subscribe to wallet events and request permissions. ```typescript import { TezosToolkit } from '@taquito/taquito'; import { BeaconWallet } from '@taquito/beacon-wallet'; const options = { name: 'MyAwesomeDapp', iconUrl: 'https://taquito.io/img/favicon.svg', network: { type: 'shadownet' }, enableMetrics: true, }; const wallet = new BeaconWallet(options); await wallet.client.subscribeToEvent( BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => { // An active account has been set, update the dApp UI console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); }, ); await wallet.requestPermissions(); const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setWalletProvider(wallet); ``` -------------------------------- ### Install Taquito Package Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Install the @taquito/taquito package using npm. ```bash npm i --save @taquito/taquito ``` -------------------------------- ### Install Taquito and Signer Packages Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-signer/README.md Install the necessary Taquito and signer packages using npm. ```bash npm i --save @taquito/taquito npm i --save @taquito/signer ``` -------------------------------- ### Install @taquito/local-forging Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-local-forging/README.md Install the local forging package using npm. ```bash npm install @taquito/local-forging ``` -------------------------------- ### Install @taquito/michelson-encoder Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-michelson-encoder/README.md Install the Michelson Encoder package using npm. ```bash npm i --save @taquito/michelson-encoder ``` -------------------------------- ### Install Taquito and Remote Signer Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-remote-signer/README.md Install the necessary Taquito and remote-signer packages using npm. ```bash npm i --save @taquito/taquito npm i --save @taquito/remote-signer ``` -------------------------------- ### Install Taquito TZIP-016 Package Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md Install the @taquito/tzip16 and @taquito/taquito packages using npm. ```bash npm i --save @taquito/tzip16 npm i --save @taquito/taquito ``` -------------------------------- ### Build and Test Taquito Project Source: https://github.com/ecadlabs/taquito/blob/main/README.md Installs project dependencies using `npm ci` for deterministic installation and then builds the Taquito project. Finally, it runs the unit tests to ensure everything is functioning correctly. ```bash npm ci npm run build npm run test ``` -------------------------------- ### Install System Libraries for Ledger Packages Source: https://github.com/ecadlabs/taquito/blob/main/README.md On some GNU/Linux systems, native dependencies for Ledger-related packages may require additional system libraries. Install these using apt on Debian or Ubuntu if npm install fails with libusb.h errors. ```bash sudo apt install -y libusb-1.0-0-dev libudev-dev pkg-config ``` -------------------------------- ### Install @taquito/tzip12 and @taquito/taquito Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip12/README.md Install the necessary packages for TZIP-12 functionality. These packages extend the Taquito contract abstraction. ```bash npm i --save @taquito/tzip12 npm i --save @taquito/taquito ``` -------------------------------- ### Install libudev-dev on Fedora/RedHat Source: https://github.com/ecadlabs/taquito/blob/main/README.md Installs the libudev-devel package on Fedora or RedHat-based Linux distributions. This is a prerequisite for building Taquito. ```bash sudo dnf install libudev-devel ``` -------------------------------- ### Install Taquito Sapling Package Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-sapling/README.md Install the package using npm. This command adds the necessary library to your project for Sapling integration. ```bash npm install @taquito/sapling ``` -------------------------------- ### Install libudev-dev on Ubuntu/Debian Source: https://github.com/ecadlabs/taquito/blob/main/README.md Installs the libudev-dev package on Ubuntu or Debian-based Linux distributions. This is a prerequisite for building Taquito. ```bash sudo apt-get install libudev-dev ``` -------------------------------- ### Run All Tests Against All Pre-configured Testnets Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Execute all integration tests against all available pre-configured Tezos testnets. Ensure Taquito source code is cloned, Node.js is installed, and Taquito is compiled. ```bash npm run test ``` -------------------------------- ### URI Decoding Example Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/src/metadataProviderRequirements.md Demonstrates how to decode a URI component using `decodeURIComponent`. This is essential for handling URIs that may contain URL-encoded characters, ensuring correct parsing of the metadata location. ```typescript decodeURIComponent('https:%2F%2Fraw.githubusercontent.com%2Ftqtezos%2FTZComet%2F8d95f7b%2Fdata%2Fmetadata_example0.json') ``` -------------------------------- ### Get Public Key Hash from Public Key Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Use `getPkhfromPk` to derive the public key hash (tz address prefix) from a given public key string. ```typescript import { getPkhfromPk } from '@taquito/utils'; const publicKey = 'sppk7czKu6So3zDWjhBPBv9wgCrBAfbEFoKYzEaKUsjhNr5Ug6E4Sn1'; console.log(getPkhfromPk(publicKey)); // output: 'tz2Gsf1Q857wUzkNGzHsJNC98z881UutMwjg ``` -------------------------------- ### Open a Chest with its Key Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-timelock/README.md Use this code to open a chest and retrieve the original data using the chest's bytes, key's bytes, and the time parameter. The 'time' parameter relates to the computational complexity, with 10000 being a recommended starting value. ```typescript import { Chest, ChestKey} from '@taquito/timelock'; //... const time = 10000; const [chest] = Chest.fromArray(chestBytes); const [chestKey] = ChestKey.fromArray(chestKeyBytes); const data = chest.open(chestKey, time); ``` -------------------------------- ### Initialize RpcClient and Fetch Balance Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-rpc/README.md Instantiate the RpcClient with an RPC URL and use it to fetch an account's balance in mutez. Ensure you have the RpcClient imported. ```typescript import { RpcClient } from '@taquito/rpc'; const client = new RpcClient('https://YOUR_PREFERRED_RPC_URL'); // Fetching the balance of an account in mutez (micro ęś©) const balance = await client.getBalance('tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb'); ``` -------------------------------- ### Initialize WalletConnect and Request Permissions Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-wallet-connect/README.md Initialize a WalletConnect instance with project ID and metadata, then request specific permissions for network, methods, and events. ```typescript import { NetworkType, PermissionScopeMethods, WalletConnect, } from '@taquito/wallet-connect'; const wallet = await WalletConnect.init({ projectId: "YOUR_PROJECT_ID", // can get YOUR_PROJECT_ID from [Reown Cloud](https://cloud.reown.com) metadata: { name: "Taquito Test Dapp", description: "Test Taquito with WalletConnect", icons: [], url: "", }, }); await wallet.requestPermissions({ permissionScope: { networks: [NetworkType.SHADOWNET], events: [], methods: [ PermissionScopeMethods.TEZOS_SEND, PermissionScopeMethods.TEZOS_SIGN, PermissionScopeMethods.TEZOS_GET_ACCOUNTS ], } }); const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setWalletProvider(wallet); ``` -------------------------------- ### Initialize Taquito with TZIP-16 Extension Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md Create a TezosToolkit instance, add the Tzip16Module as an extension, and attach it to a contract abstraction. ```javascript import { TezosToolkit } from '@taquito/taquito'; import { Tzip16Module } from '@taquito/tzip16'; import { tzip16 } from '@taquito/tzip16'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.addExtension(new Tzip16Module()); const contract = await Tezos.contract.at("contractAddress", tzip16) ``` -------------------------------- ### Initialize LedgerSigner with WebHID Transport Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-ledger-signer/README.md Import and create an instance of the WebHID transport, then use it to initialize the LedgerSigner. This is for web applications. ```typescript import transportWeb from '@ledgerhq/hw-transport-webhid'; import { LedgerSigner } from '@taquito/ledger-signer'; const transport = await transportWeb.create(); const ledgerSigner = new LedgerSigner(transport); ``` -------------------------------- ### Get Contract Metadata Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md Retrieves the metadata associated with a TZIP-016 compliant smart contract. The metadata includes the URI, the JSON metadata content, and optional integrity check information. ```APIDOC ## Get Contract Metadata After extending the contract abstraction with TZIP-16, you can retrieve the contract's metadata using the `getMetadata` method. ### Method Signature ```ts contract.tzip16().getMetadata(): Promise ``` ### Description This method fetches the metadata from the contract's storage, decodes the URI, retrieves the metadata content (from on-chain, HTTP(S), or IPFS), and performs an integrity check if a SHA256 hash is provided. ### Return Value The method returns a `Tzip16Metadata` object containing: - `uri`: The URI pointing to the metadata. - `metadata`: The parsed metadata in JSON format. - `sha256Hash`: An optional SHA256 hash of the metadata for integrity verification. - `integrityCheckResult`: An optional result indicating if the integrity check passed. ### Example ```ts const metadata = await contract.tzip16().getMetadata(); console.log(metadata.metadata); ``` ``` -------------------------------- ### Instantiate TezosToolkit with RPC URL Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Instantiate the TezosToolkit with an RPC URL to create a default RpcClient instance for network interaction. ```typescript import { TezosToolkit } from '@taquito/taquito'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); ``` -------------------------------- ### Keygen API Sequence Diagram Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Illustrates the interaction flow between User, Keygen service, and Redis for ephemeral key management and signing operations. ```mermaid sequenceDiagram participant User participant Keygen participant Redis User->>+Keygen: Get Ephemeral Key Keygen->>+Redis: Pop Key from pool Keygen->>+Redis: Create lease entry in Redis (with expiry date) Keygen-->>+User: Return Ephemeral Key Lease ID User->>+User: Create a remote signer with Lease ID loop User->>+Keygen: Sign Operation Keygen->>+Redis: Retrieve private key to sign based on Lease ID Keygen->>+Keygen: Sign user data Keygen-->>+User: Return Signed Operation end Redis->>+Redis: Remove lease entry Redis->>+Keygen: Publish removal event Keygen->>+Redis: Add key to pool if amount is smaller than spendable amount User->>+Keygen: 404 :[ ``` -------------------------------- ### Create and Use HttpBackend Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-http-utils/README.md Instantiate HttpBackend and use its createRequest method to construct an HTTP request. The response type can be specified using generics. ```typescript import { HttpBackend } from '@taquito/http-utils'; const httpBackend = new HttpBackend(); const response = httpBackend.createRequest({ url: `/chains/${chain}/blocks/${block}/context/contracts/${address}/script`, method: 'GET', headers: { 'Content-Type': 'text/plain; charset=utf-8' }, json: false }); ``` -------------------------------- ### Create KV Namespace with Wrangler Source: https://github.com/ecadlabs/taquito/blob/main/website/src/cloudflare/chatkit/README.md Use the wrangler CLI to create a KV namespace for rate limiting. Copy the output ID and update your wrangler.jsonc file. ```bash wrangler kv namespace create RATE_LIMIT ``` ```json "kv_namespaces": [ { "binding": "RATE_LIMIT", "id": "YOUR_KV_ID_HERE" } ] ``` -------------------------------- ### Initialize LedgerSigner with Optional Parameters Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-ledger-signer/README.md Initialize the LedgerSigner with custom derivation path, prompt setting, and derivation type. The default values are path='44'/1729'/0'/0', prompt=true, and derivationType=DerivationType.ED25519. ```typescript import { LedgerSigner, DerivationType, HDPathTemplate } from '@taquito/ledger-signer'; const ledgerSigner = new LedgerSigner( transport, //required HDPathTemplate(1), // path optional (equivalent to "44'/1729'/1'/0'") true, // prompt optional DerivationType.ED25519 // derivationType optional ); ``` -------------------------------- ### Add Contracts to ContractsLibrary Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-contracts-library/README.md Instantiate ContractsLibrary and add contract details including script and entrypoints. Then, add the ContractsLibrary instance as an extension to your TezosToolkit instance. ```typescript import { ContractsLibrary } from '@taquito/contracts-library'; const contractsLibrary = new ContractsLibrary(); contractsLibrary.addContract({ 'contractAddress1': { script: script1, // obtained from Tezos.rpc.getNormalizedScript('contractAddress1') entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1') }, 'contractAddress2': { script: script2, entrypoints: entrypoints2 } }) Tezos.addExtension(contractsLibrary); ``` -------------------------------- ### Configure Wallet API with BeaconWallet Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Configure the TezosToolkit to use the Wallet API by setting a BeaconWallet. This allows dapps to interact with user-chosen wallets. ```typescript import { TezosToolkit } from '@taquito/taquito'; import { BeaconWallet } from '@taquito/beacon-wallet'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); const wallet = new BeaconWallet(options); await wallet.requestPermissions(network); Tezos.setWalletProvider(wallet); // Using the wallet API, the configured wallet will prepare the transaction and broadcast it await Tezos.wallet.transfer({ to: publicKeyHash, amount: 2 }).send(); ``` -------------------------------- ### Configure Local Forger with TezosToolkit Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-local-forging/README.md Set up the TezosToolkit instance and configure it to use the local forger by providing the LocalForger instance to the setProvider method. ```typescript import { TezosToolkit } from '@taquito/taquito' import { LocalForger } from '@taquito/local-forging' const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setProvider({ forger: localForger }) ``` -------------------------------- ### Configure WalletConnect with Existing Session Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-wallet-connect/README.md Restore an existing WalletConnect session using a session key. The session is validated before activation. ```typescript const existingSessionKey = wallet.getAllExistingSessionKeys()[0]; if (existingSessionKey) { wallet.configureWithExistingSessionKey(existingSessionKey); } ``` -------------------------------- ### Use a Secret Key Instead of Keygen API Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Run integration tests using a provided secret key instead of the default Keygen API. This requires setting the `SECRET_KEY` environment variable and ensuring the associated account has a non-zero balance. ```bash npm run test:tallinnnet-secret-key contract-with-bigmap-init.spec.ts ``` ```bash export SECRET_KEY='edsk...' ``` -------------------------------- ### Use LedgerSigner with Taquito Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-ledger-signer/README.md Set up Taquito with the LedgerSigner and retrieve the public key and public key hash from the Ledger device. Ensure you have a preferred RPC URL configured. ```typescript import { LedgerSigner } from '@taquito/ledger-signer'; import TransportWeb from '@ledgerhq/hw-transport-webhid'; import { TezosToolkit } from '@taquito/taquito'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); const transport = await TransportWeb.create(); const ledgerSigner = new LedgerSigner(transport); Tezos.setProvider({ signer: ledgerSigner }); //Get the public key and the public key hash from the Ledger const publicKey = await Tezos.signer.publicKey(); const publicKeyHash = await Tezos.signer.publicKeyHash(); ``` -------------------------------- ### Execute Off-Chain Views Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md Initialize and execute off-chain views defined in the contract's metadata using the metadataViews method. ```javascript // Initialize off-chain views const metadataViews = await contractAbstraction.tzip16().metadataViews(); const viewResult = await metadataViews.nameOfTheView().executeView(paramOfTheView); ``` -------------------------------- ### Initialize Schema with Michelson Storage Type Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-michelson-encoder/README.md Create a Schema instance by providing the contract's storage type in Michelson format. This schema is used for subsequent data encoding and decoding. ```typescript const storageType = { prim: 'pair', args: [ { prim: 'nat', annots: [ '%stored_counter' ] }, { prim: 'pair', args: [ { prim: 'nat', annots: [ '%threshold' ] }, { prim: 'list', args: [ { prim: 'key' } ], annots: [ '%keys' ] } ] } ] }; const storageSchema = new Schema(storageType); ``` -------------------------------- ### Create a Chest from an Existing Timelock Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-timelock/README.md This snippet demonstrates how to create a chest and key using a precomputed Timelock. The `Timelock.precompute` function can be cached for efficiency. Ensure the payload is encoded to bytes. ```typescript import { Chest, Timelock } from '@taquito/timelock'; // ... const time = 10000; const precomputedTimelock = Timelock.precompute(time); // can be cached const { chest, key } = Chest.fromTimelock(payload, time, precomputedTimelock); const chestBytes = chest.encode(); const keyBytes = key.encode(); ``` -------------------------------- ### Execute Off-Chain Views Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md Allows execution of off-chain views defined in the smart contract's TZIP-016 metadata. This enables interaction with custom logic exposed through metadata. ```APIDOC ## Execute Off-Chain Views If a contract's TZIP-016 metadata includes off-chain views, the `@taquito/tzip16` package allows you to execute them directly. ### Method Signature ```ts contractAbstraction.tzip16().metadataViews(): Promise ``` ### Description First, you need to initialize the off-chain views by calling `metadataViews()`. This returns an object where each property corresponds to a view name. You can then call the view by its name and execute it with optional parameters. ### Example ```ts // Initialize off-chain views const metadataViews = await contractAbstraction.tzip16().metadataViews(); // Execute a view named 'nameOfTheView' with a parameter 'paramOfTheView' const viewResult = await metadataViews.nameOfTheView().executeView(paramOfTheView); ``` Replace `nameOfTheView` with the actual name of the off-chain view and `paramOfTheView` with the required parameter for that view. ``` -------------------------------- ### Deploy the Cloudflare Worker Source: https://github.com/ecadlabs/taquito/blob/main/website/src/cloudflare/chatkit/README.md Use the npm script to deploy the Cloudflare Worker. ```bash npm run deploy ``` -------------------------------- ### Include Taquito CDN Bundle Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Include the Taquito minified JavaScript bundle from a CDN to use the library in a browser environment. ```html ``` -------------------------------- ### Run Tests Against a Specific RPC URL Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Configure integration tests to run against a custom Tezos RPC endpoint by exporting the `TEZOS_RPC_` environment variable. This is useful for testing against local nodes or non-standard deployments. ```bash export TEZOS_RPC_TALLINNNET='http://localhost:8732' ``` -------------------------------- ### Run All Tests Against a Specific Testnet Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Target a specific Tezos testnet for running all integration tests by setting an environment variable. Refer to `taquito/integration-tests/config.ts` for available testnets and their corresponding environment variables. ```bash TALLINNNET=true npm run test ``` -------------------------------- ### Configure Contract API with InMemorySigner Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Configure the TezosToolkit to use the Contract API by setting an InMemorySigner. This is suitable for backend applications or offline signing. ```javascript import { InMemorySigner } from '@taquito/signer'; import { TezosToolkit } from '@taquito/taquito'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey('edsk...') }); // Using the contract API, the follwing operation is signed using the configured signer: await Tezos.contract.transfer({ to: publicKeyHash, amount: 2 }); ``` -------------------------------- ### Run Tests on a Specific Testnet Using CLI Parameter Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Execute integration tests for a specific testnet by providing the testnet name as a CLI parameter. This is useful when multiple testnets are configured in `config.ts`. ```bash npm run test:tallinnnet contract-with-bigmap-init.spec.ts ``` -------------------------------- ### Extend Taquito Contract Abstraction with TZIP-12 Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip12/README.md Create an instance of Tzip12Module and add it as an extension to TezosToolkit. Use the tzip12 function to extend a contract abstraction, allowing you to call TZIP-12 methods. ```typescript import { TezosToolkit } from '@taquito/taquito'; import { Tzip12Module } from '@taquito/tzip12'; import { tzip12 } from '@taquito/tzip12'; import BigNumber from 'bignumber.js'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.addExtension(new Tzip12Module()); const contract = await Tezos.contract.at("contractAddress", tzip12) // get the token metadata await contract.tzip12().getTokenMetadata(BigNumber(1)); ``` -------------------------------- ### Run a Specific Test Within a Test File Source: https://github.com/ecadlabs/taquito/blob/main/integration-tests/README.md Execute a particular test case within a specified test file by using the `-t` flag with a descriptive test title. This allows for focused testing of individual scenarios. ```bash npm run test:tallinnnet -- -t "Verify contract.originate for a contract and call deposit method with unit param" ``` -------------------------------- ### Create ChatKit Session Source: https://github.com/ecadlabs/taquito/blob/main/website/src/cloudflare/chatkit/README.md This endpoint is used to initiate a new session with OpenAI's ChatKit. It does not require any parameters in the request body. ```APIDOC ## POST /api/chatkit/session ### Description Creates a new ChatKit session. ### Method POST ### Endpoint /api/chatkit/session ### Request Body No body required ### Response #### Success Response (200) - **client_secret** (string) - A short-lived token for the session. - **expires_after** (integer) - The duration in seconds until the token expires. ### Response Example { "client_secret": "ck_live_...", "expires_after": 3600 } ``` -------------------------------- ### Lint, Test, and Commit Taquito Changes Source: https://github.com/ecadlabs/taquito/blob/main/README.md Runs linting and unit tests on modified Taquito source code before committing. Ensure changes are well-tested and linted. Use a conventional commit message for the final commit. ```bash npm run lint npm run test git commit ``` -------------------------------- ### Convert Buffer to Hexadecimal String and vice versa Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Utilize `buf2hex` to convert a Node.js Buffer to its hexadecimal string representation and `hex2buf` to convert a hexadecimal string back into a Buffer. ```typescript import { buf2hex, hex2buf } from '@taquito/utils'; const buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); const hex = '627566666572' console.log(buf2hex(buffer)); // output: 627566666572 console.log(hex2buf(hex)); // output: Uint8Array(6) [ 98, 117, 102, 102, 101, 114 ] ``` -------------------------------- ### Integrate RpcClientCache with TezosToolkit Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-rpc/README.md Use RpcClientCache to enhance dApp performance by caching RPC responses. Inject the RpcClientCache instance into the TezosToolkit. The cache has a default time-to-live of 1000 milliseconds. ```typescript import { TezosToolkit } from '@taquito/taquito'; import { RpcClient, RpcClientCache } from '@taquito/rpc'; const rpcClient = new RpcClient('https://YOUR_PREFERRED_RPC_URL'); const tezos = new TezosToolkit(new RpcClientCache(rpcClient)); ``` -------------------------------- ### Taquito API Documentation Source: https://github.com/ecadlabs/taquito/blob/main/README.md TypeDoc API documentation for Taquito is available at the provided link. This documentation details the interfaces, classes, and functions available within the Taquito SDK for developers. ```APIDOC ## API Documentation TypeDoc API documentation for Taquito is [available here](https://taquito.io/typedoc). ``` -------------------------------- ### MetadataProvider Interface Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/src/metadataProviderRequirements.md The MetadataProvider interface defines the contract for fetching metadata. It includes a `provideMetadata` method that takes a URI and contract abstraction to retrieve metadata, returning a MetadataEnvelope. ```APIDOC ## Interface: MetadataProvider ### Description Provides a method to fetch metadata from a given URI. It supports various protocols like HTTP, HTTPS, IPFS, and Tezos storage. ### Methods #### `provideMetadata(uri: String, contractAbstraction: ContractAbstraction): Promise` - **Description**: Fetches the metadata. The `uri` parameter contains the required information to locate metadata contents (http/https, ipfs, tezos-storage). - **Parameters**: - `uri` (String) - The decoded URI pointing to the metadata. - `contractAbstraction` (ContractAbstraction) - The contract abstraction of the current contract, useful if metadata are located inside its own storage. - **Returns**: - `Promise` - A promise that resolves to a MetadataEnvelope object representing the metadata. ``` -------------------------------- ### Configure RemoteSigner with TezosToolkit Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-remote-signer/README.md Inject the RemoteSigner into the TezosToolkit to enable remote signing for operations. The signer requires the public key hash and the remote signer's URL. ```typescript import { TezosToolkit } from '@taquito/taquito'; import { RemoteSigner } from '@taquito/remote-signer'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); const signer = new RemoteSigner(pkh, rootUrl); Tezos.setSignerProvider(signer); // Taquito will send a request to the configured Remote Signer to sign the transfer operation: await Tezos.contract.transfer({ to: publicKeyHash, amount: 2 }); ``` -------------------------------- ### Create a New Chest and Key Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-timelock/README.md Use this snippet to generate a new chest and its corresponding key. The 'time' parameter influences the complexity of key computation. A payload is encoded into bytes before being used. ```typescript import { Chest } from '@taquito/timelock' const time = 10000; const payload = new TextEncoder().encode('message'); const { chest, key } = Chest.newChestAndKey(payload, time); const chestBytes = chest.encode(); const keyBytes = key.encode(); ``` -------------------------------- ### Extending Contract Abstraction with TZIP-16 Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/README.md This snippet shows how to add the Tzip16Module to Taquito and use the tzip16 function to extend a contract abstraction, enabling TZIP-16 features. ```APIDOC ## Extending Contract Abstraction with TZIP-16 To enable TZIP-016 functionality for a contract, you need to add the `Tzip16Module` to your `TezosToolkit` instance and then use the `tzip16` function when fetching the contract. ### Usage ```js import { TezosToolkit } from '@taquito/taquito'; import { Tzip16Module } from '@taquito/tzip16'; import { tzip16 } from '@taquito/tzip16'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.addExtension(new Tzip16Module()); const contract = await Tezos.contract.at("contractAddress", tzip16); ``` This setup allows you to call TZIP-16 related methods on the `contract` object. ``` -------------------------------- ### Prepare a Shielded Transaction Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-sapling/README.md Prepare a shielded transaction to send tokens from a Tezos account to a Sapling address. This involves fetching a payment address and then using the SaplingToolkit to construct the transaction. The amount must be specified when sending the operation. ```typescript import { TezosToolkit, RpcReadAdapter } from '@taquito/taquito'; import { SaplingToolkit, InMemorySpendingKey } from '@taquito/sapling'; const tezos = new TezosToolkit('https://shadownet.tezos.ecadinfra.com/'); // set up your signer on the TezosToolkit as usual const saplingContract = await tezos.contract.at('KT1UYwMR6Q6LZnwQEi77DSBrAjKT1tEJb245'); const inMemorySpendingKey = await InMemorySpendingKey.fromMnemonic('YOUR_MNEMONIC'); const readProvider = new RpcReadAdapter(tezos.rpc); const saplingToolkit = new SaplingToolkit( { saplingSigner: inMemorySpendingKey }, { contractAddress: saplingContract.address, memoSize: 8 }, readProvider ) // Fetch a payment address (zet) const inMemoryViewingKey = await inMemorySpendingKey.getSaplingViewingKeyProvider(); const paymentAddress = (await inMemoryViewingKey.getAddress()).address; // prepare the shielded transaction const shieldedTx = await saplingToolkit.prepareShieldedTransaction([{ to: paymentAddress, amount: 3, memo: 'test', mutez: false // set to false by default }]) // Inject the sapling transaction using the ContractAbstraction // The amount MUST be specified in the send method to transfer the 3 tez to the shielded set const op = await saplingContract.methodsObject.default([shieldedTx]).send({ amount: 3 }); await op.confirmation(); ``` -------------------------------- ### Load Unencrypted Private Key with InMemorySigner Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-signer/README.md Configure Taquito to use an InMemorySigner by loading an unencrypted private key. This allows automatic signing of operations. ```javascript import { InMemorySigner } from '@taquito/signer'; import { TezosToolkit } from '@taquito/taquito'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey('edsk...') }); ``` -------------------------------- ### Metadata Provider Interface Definition Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-tzip16/src/metadataProviderRequirements.md Defines the contract for a metadata provider. It specifies a single method, `provideMetadata`, which fetches metadata given a URI and contract abstraction. This interface is crucial for abstracting different metadata fetching strategies. ```typescript export interface MetadataProvider { /** * @description Fetch the metadata. The uri parameter contains the required information to locate metadata contents (http/https, ipfs, tezos-storage). * @returns An object representing the metadata * @param contractAbstraction the contractAbstraction of the current contract (useful if metadata are located inside its own storage) * @param uri the decoded uri */ provideMetadata(uri: String, contractAbstraction: ContractAbstraction): Promise; } ``` -------------------------------- ### Decode and Check Base58 Prefix Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Use `b58DecodeAndCheckPrefix` to decode a Base58 string and verify its prefix against a list of allowed prefixes. The `removePrefix` option can be set to true to strip the prefix after decoding. ```typescript import { b58DecodeAndCheckPrefix, PrefixV2 } from '@taquito/utils'; console.log(b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash], true)); // output: ``` -------------------------------- ### Set OpenAI Secrets with Wrangler Source: https://github.com/ecadlabs/taquito/blob/main/website/src/cloudflare/chatkit/README.md Use the wrangler CLI to set your OpenAI API key and ChatKit workflow ID as secrets for the worker. ```bash wrangler secret put OPENAI_API_KEY ``` ```bash wrangler secret put CHATKIT_WORKFLOW_ID ``` -------------------------------- ### Configure Polling Interval for Operation Confirmation Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Set the polling interval and timeout for operation confirmation globally for a Taquito instance. ```javascript Tezos.setProvider( { config: { confirmationPollingIntervalSecond: 5, confirmationPollingTimeoutSecond: 180 } } ) ``` -------------------------------- ### Convert String to Bytes and Bytes to String Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Use `stringToBytes` to convert a string to its byte representation (hexadecimal) and `bytesToString` to convert a hexadecimal string back to a human-readable string. ```typescript import { stringToBytes, bytesToString } from '@taquito/utils'; const url = 'https://storage.googleapis.com/tzip-16/fa2-views.json'; const hex = '68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e'; console.log(stringToBytes(url)); // output: 68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e console.log(bytesToString(hex)); // output: https://storage.googleapis.com/tzip-16/fa2-views.json ``` -------------------------------- ### Validate Tezos Public Key Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-utils/README.md Use `validatePublicKey` to ensure a string conforms to the Tezos public key format. ```typescript import { validatePublicKey } from '@taquito/utils'; const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g'; console.log(validatePublicKey(publicKey)); // output: 3 which is valid ``` -------------------------------- ### Clean Taquito Build Artifacts Source: https://github.com/ecadlabs/taquito/blob/main/README.md Recursively deletes build artifacts from the Taquito project. Use this command instead of manually deleting `node_modules/` to avoid confusing the build system. ```bash npm run clean ``` -------------------------------- ### Load Encrypted Private Key with Passphrase Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito-signer/README.md Configure Taquito to use an InMemorySigner with an encrypted private key by providing a passphrase for decryption. This enables signing transactions using the decrypted key. ```javascript import { InMemorySigner } from '@taquito/signer'; import { TezosToolkit } from '@taquito/taquito'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey('your_private_key', 'your_passphrase'), }); ``` -------------------------------- ### Estimate Transfer Operation Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Use the `estimate` member of the TezosToolkit to estimate fees, gas, and storage for transfer operations. ```typescript const estimate = await Tezos.estimate.transfer(transferParams); ``` -------------------------------- ### Set LocalForger Provider Source: https://github.com/ecadlabs/taquito/blob/main/packages/taquito/README.md Replace the default RpcForger with an instance of LocalForger for local forging capabilities. ```typescript import { localForger } from '@taquito/local-forger' Tezos.setForgerProvider(localForger); ```