### Default Wax Initialization in JavaScript Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/config/init-general Initializes the Hive Chain using default options provided by the `@hiveio/wax` library. This is the simplest way to get started with Wax. ```javascript import { createHiveChain } from '@hiveio/wax'; // Initialize Hive Chain using default options await createHiveChain(); ``` -------------------------------- ### Install MetaMask Signer Package for Wax Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/metamask Installs the @hiveio/wax-signers-metamask package using pnpm. This package provides the necessary functionality to use MetaMask as a signer for Wax. ```bash pnpm add @hiveio/wax-signers-metamask ``` -------------------------------- ### Creating Blog Posts and Replies on Hive Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This example shows how to create and push both a blog post (`BlogPostOperation`) and a reply (`ReplyOperation`) into a transaction. It covers setting various fields for comments, including author, permlink, title, body, category, tags, and payout options. The transaction is then signed and logged. ```javascript const commentOperationTx = await chain.createTransaction(); commentOperationTx.pushOperation(new BlogPostOperation({ author: accountName, permlink: 'my-article-permlink', title: 'My article title', body: 'My article body', category: 'my-category', tags: ['my-article'], description: 'This is my article!', images: ['article.jpg'], links: ['https://example.com'], format: ECommentFormat.MARKDOWN, beneficiaries: [{ account: 'friend', weight: 40 }], maxAcceptedPayout: chain.hbdCoins(100), allowCurationRewards: true, allowVotes: true })); commentOperationTx.pushOperation(new ReplyOperation({ author: accountName, permlink: 'My-reply-permlink', parentAuthor: accountName, parentPermlink: 'my-article-permlink', body: 'My reply body', tags: ['my-reply'], description: 'This is my reply!', images: ['reply.jpg'], links: ['https://example.com'], format: ECommentFormat.MARKDOWN, beneficiaries: [{ account: 'friend', weight: 40 }], maxAcceptedPayout: chain.hbdCoins(100), allowCurationRewards: true, allowVotes: true })); commentOperationTx.sign(wallet, publicPostingSigningKey); console.log(commentOperationTx.toApi()); // await chain.broadcast(otherOperationsTx); ``` -------------------------------- ### Usage Example: PeakVault Signer with Wax Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/peakvault A JavaScript example demonstrating how to integrate the PeakVault signer with the Wax library. It shows how to create a Wax interface, set up the PeakVault provider, create a transaction, sign it using Peak Vault, and broadcast it. Requires a configured Peak Vault extension. ```javascript import { createHiveChain } from "@hiveio/wax"; import PeakVaultProvider from "@hiveio/wax-signers-peakvault"; const chain = await createHiveChain(); const provider = PeakVaultProvider.for("myaccount", "active"); // Create a transaction using the Wax Hive chain instance const tx = await chain.createTransaction(); // Perform some operations, e.g. push the vote operation: tx.pushOperation({ vote_operation: { voter: "alice", author: "bob", permlink: "example-post", weight: 10000 } }); // Wait for the keychain to sign the transaction await provider.signTransaction(tx); // broadcast the transaction await chain.broadcast(tx); ``` -------------------------------- ### Usage Example: Sign Hive Transaction with Keychain Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/keychain Demonstrates how to use the Keychain provider with the Wax library to create, sign, and broadcast a Hive transaction. It requires a configured Keychain browser extension and imported keys. The example includes pushing a vote operation and signing it using the 'myaccount' with 'active' authority. ```typescript import { createHiveChain } from "@hiveio/wax"; import KeychainProvider from "@hiveio/wax-signers-keychain"; const chain = await createHiveChain(); const provider = KeychainProvider.for("myaccount", "active"); // Create a transaction using the Wax Hive chain instance const tx = await chain.createTransaction(); // Perform some operations, e.g. push the vote operation: tx.pushOperation({ vote_operation: { voter: "alice", author: "bob", permlink: "example-post", weight: 10000 } }); // Wait for the keychain to sign the transaction await provider.signTransaction(tx); // broadcast the transaction await chain.broadcast(tx); ``` -------------------------------- ### Comment and Comment Options Transaction Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet demonstrates creating a post (comment) and then setting options for that post, such as payout and beneficiaries. It also includes an example of a reply to the initial post. ```json { "ref_block_num": 32100, "ref_block_prefix": 27252558, "expiration": "2024-07-02T15:56:28", "operations": [ { "type": "comment_operation", "value": { "parent_author": "", "parent_permlink": "my-category", "author": "your-account", "permlink": "my-article-permlink", "title": "My article title", "body": "My article body", "json_metadata": "{\"format\":\"markdown\",\"app\":\"@hiveio/wax/1.27.6-rc1\",\"tags\":[\"my-article\"],\"description\":\"This is my article!\",\"image\":[\"article.jpg\"],\"links\":[\"https://example.com\"]}" } }, { "type": "comment_options_operation", "value": { "author": "your-account", "permlink": "my-article-permlink", "max_accepted_payout": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "percent_hbd": 10000, "allow_votes": true, "allow_curation_rewards": true, "extensions": [ { "type": "comment_payout_beneficiaries", "value": { "beneficiaries": [ { "account": "friend", "weight": 40 } ] } } ] } }, { "type": "comment_operation", "value": { "parent_author": "your-account", "parent_permlink": "my-article-permlink", "author": "your-account", "permlink": "re-your-account-1719935728826", "title": "", "body": "My reply body", "json_metadata": "{\"format\":\"markdown\",\"app\":\"@hiveio/wax/1.27.6-rc1\",\"tags\":[\"my-reply\"],\"description\":\"This is my reply!\",\"image\":[\"reply.jpg\"],\"links\":[\"https://example.com\"]}" } }, { "type": "comment_options_operation", "value": { "author": "your-account", "permlink": "re-your-account-1719935728826", "max_accepted_payout": {"amount": "100", "precision": 3, "nai": "@@000000021"}, "percent_hbd": 10000, "allow_votes": true, "allow_curation_rewards": true, "extensions": [] } } ], "signatures": [ "20768549f9e17688287c6e511a1efa170834dd5ef0662e737de47a874876b83a4812a2f38d1386c1d2ab2ae055282f1ada76646434ad87377a78988c70de36a7ed" ] } ``` -------------------------------- ### Install Keychain Signer Package Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/keychain Installs the Keychain signer package using pnpm. Ensure you have pnpm installed and configured for your project. This package enables transaction signing via the third-party Keychain browser extension. ```bash pnpm add @hiveio/wax-signers-keychain ``` -------------------------------- ### Create and Multi-Sign Hive Transaction (JavaScript) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Example of creating a Hive transaction with comment and comment options operations, then signing it using two different signers. It demonstrates multi-signing capabilities and conversion to the Hive API format. Dependencies include the '@hiveio/wax' library. ```javascript import { createHiveChain, ReplyOperation } from '@hiveio/wax'; // Initialize chain const chain = await createHiveChain(); // Retrieve the signers const { signer1, signer2 } = globalThis.snippetsBeekeeperData; // Create a transaction const tx = await chain.createTransaction(); // Use the ReplyOperation to create a reply operation tx.pushOperation(new ReplyOperation({ parentAuthor: 'parent-author', parentPermlink: 'parent-permlink', author: 'author', body: 'body', beneficiaries: [{ account: 'test', weight: 40 }], tags: ['tag'], description: 'description', })); // Convert the transaction into the Hive API-form JSON const apiTx = tx.toApi(); // log apiTransaction console.log(apiTx); // Apply the transaction in the API form into transaction interface const txFromApi = chain.createTransactionFromJson(apiTx); await signer1.signTransaction(txFromApi); // Log txSigned console.log(txFromApi.toApi()); await signer2.signTransaction(txFromApi); // log multi signed transaction console.log(txFromApi.toApi()); /* * Call actual broadcast API to send transaction to the blockchain. * The code is commented out because examples does not have access to Hive mainnet keys. */ // await chain.broadcast(txFromApi); ``` -------------------------------- ### Install Beekeeper Signer Package Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/beekeeper Instructions for installing the Beekeeper signer package using pnpm. This package is required to integrate Beekeeper's secure wallet functionality with the Wax library for transaction signing. ```bash pnpm add @hiveio/wax-signers-beekeeper ``` -------------------------------- ### Manage HiveAppsOperations (Follow, RC, Community) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet illustrates how to use HiveAppsOperations to manage social interactions and resources on the Hive blockchain. It includes examples for following/muting users, reblogging posts, delegating resource credits, subscribing to communities, and flagging posts. The transaction is signed and logged, with the broadcast commented out. ```javascript const otherOperationsTx = await chain.createTransaction(); const followOperation = new FollowOperation(); otherOperationsTx.pushOperation( followOperation .followBlog(accountName, 'blog-to-follow') .muteBlog(accountName, 'blog-to-mute') .reblog(accountName, 'to-reblog', 'post-permlink') .authorize(accountName) ); const rcOperation = new ResourceCreditsOperation(); otherOperationsTx.pushOperation( rcOperation .delegate(accountName, 1000, 'friend') .authorize(accountName) ); const communityOperation = new CommunityOperation(); const communityName = 'community-name'; otherOperationsTx.pushOperation( communityOperation .subscribe('communityName') .flagPost(communityName, 'author-account', 'post-permlink', 'violation notes') .authorize(accountName) ); otherOperationsTx.sign(wallet, publicPostingSigningKey); console.log(otherOperationsTx.toApi()); // await chain.broadcast(otherOperationsTx); ``` -------------------------------- ### Install and Use HAfAH REST API Package (JavaScript) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/api/extend-api This snippet demonstrates how to install and import the HAfAH REST API package from npmjs. It then shows how to extend a chain object with the REST API, enabling access to its methods. ```javascript import HAfAH from "@hiveio/wax-api-hafah"; const extendedChain = chain.extendRest(HAfAH); // You can now call extendedChain.restApi...() ``` -------------------------------- ### Initialize Wax API, Chain, and Beekeeper Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Initializes the Wax API, Hive chain, and Beekeeper for session and wallet management. This sets up the necessary components for creating and signing transactions. ```javascript import beekeeperFactory from '@hiveio/beekeeper'; import { createHiveChain, createWaxFoundation, ReplyOperation, BlogPostOperation, ECommentFormat, DefineRecurrentTransferOperation, UpdateProposalOperation, WitnessSetPropertiesOperation, FollowOperation, ResourceCreditsOperation, CommunityOperation, AccountAuthorityUpdateOperation } from '@hiveio/wax'; // Initialize wax api const waxApi = await createWaxFoundation(); // Initialize chain const chain = await createHiveChain(); // Initialize beekeeper const beekeeper = await beekeeperFactory(); // Create session const session = beekeeper.createSession('salt'); // Create wallet const { wallet } = await session.createWallet('w1'); ``` -------------------------------- ### Object Traversal Example in Wax Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/formatters/preface Demonstrates the bottom-up object traversal order used by Wax transformers. Properties are matched from the innermost to the outermost without modifying the input data. ```json { "b": { "a": 10 }, "c": 20 } ``` -------------------------------- ### Install HB Auth Signer Package Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/hb-auth Instructions to install the HB Auth signer package using pnpm. This package provides the necessary tools to integrate HB Auth with the Wax library. ```bash pnpm add @hiveio/wax-signers-hb-auth ``` -------------------------------- ### Generate and Import Keys for Transaction Signing Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Generates posting, active, and encryption private keys from a master password and imports them into the wallet. This is crucial for signing transactions and encrypting memos. ```javascript // Declare example account name const accountName = "your-account"; // Declare example password for generating private key const masterPassword = "your-master-password"; // Generating a new posting private key from a password const privatePostingKeyData = waxApi.getPrivateKeyFromPassword( accountName, 'posting', masterPassword ); // Import the posting key into the wallet const publicPostingSigningKey = await wallet.importKey( privatePostingKeyData.wifPrivateKey ); // Generating a new active private key from a password const privateActiveKeyData = waxApi.getPrivateKeyFromPassword( accountName, 'active', masterPassword ); // Import the active key into the wallet const publicActiveSigningKey = await wallet.importKey( privateActiveKeyData.wifPrivateKey ); // Generating a new encryption private key from a password const privateEncryptionKeyData = waxApi.getPrivateKeyFromPassword( accountName, 'memo', masterPassword ); // Import the encryption key into the wallet const publicEncryptionSigningKey = await wallet.importKey( privateEncryptionKeyData.wifPrivateKey ); ``` -------------------------------- ### Create and Sign a Simple Vote Operation Transaction Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Creates a simple transaction, adds a vote operation, signs it using the posting key, and logs the transaction in API form. This demonstrates basic transaction construction and signing. ```javascript // Create a transaction const simpleOperationTx = await chain.createTransaction(); const voteOp = { vote_operation: { voter: "voter", author: "author", permlink: "test-permlink", weight: 2200 } }; // Push simple vote operation into previously initialized transaction simpleOperationTx.pushOperation(voteOp); // Sign and build the transaction simpleOperationTx.sign(wallet, publicPostingSigningKey); // Log the simple transaction into console in API form console.log(simpleOperationTx.toApi()); /* * Call actual broadcast API to send transaction to the blockchain. * The code is commented out because examples does not have access to * Hive mainnet keys. */ // await chain.broadcast(simpleOperationTx); ``` -------------------------------- ### Install PeakVault Signer Package Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/peakvault Instructions on how to add the PeakVault signer package to your project using pnpm. This package is required to enable transaction signing with the Peak Vault browser extension. ```bash pnpm add @hiveio/wax-signers-peakvault ``` -------------------------------- ### Create and Broadcast Hive Operations Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet demonstrates creating a transaction and pushing various operation types to it: DefineRecurrentTransferOperation, UpdateProposalOperation, and WitnessSetPropertiesOperation. It then signs and logs the transaction in API format. The actual broadcast is commented out. ```javascript const operationFactoriesTx = await chain.createTransaction(); operationFactoriesTx.pushOperation(new DefineRecurrentTransferOperation({ from: accountName, to: 'friend', amount: chain.hiveCoins(100), memo: 'Daily pay', recurrence: 24, executions: 30 })); operationFactoriesTx.pushOperation(new UpdateProposalOperation({ proposalId: 1, creator: accountName, dailyPay: chain.hbdCoins(100), subject: 'Proposal Update', permlink: 'proposal-update', endDate: '2023-03-14', })); operationFactoriesTx.pushOperation(new WitnessSetPropertiesOperation({ owner: accountName, witnessSigningKey: publicActiveSigningKey, maximumBlockSize: 65536, hbdInterestRate: 750, accountCreationFee: chain.hiveCoins(300), url: "https://example.com" })); operationFactoriesTx.sign(wallet, publicActiveSigningKey); console.log(operationFactoriesTx.toApi()); // await chain.broadcast(otherOperationsTx); ``` -------------------------------- ### POST /operations/proposal_update Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Updates an existing proposal on the blockchain. This can include changing parameters like daily pay, subject, or end date. ```APIDOC ## POST /operations/proposal_update ### Description Updates an existing proposal on the blockchain. This can include changing parameters like daily pay, subject, or end date. ### Method POST ### Endpoint /operations/proposal_update ### Parameters #### Request Body - **proposal_id** (string) - Required - The unique identifier of the proposal to update. - **creator** (string) - Required - The account name that created the proposal. - **daily_pay** (object) - Optional - The new daily payment amount for the proposal. - **amount** (string) - Required - The numerical value of the amount. - **precision** (integer) - Required - The number of decimal places for the amount. - **nai** (string) - Required - The NAI (Numeric Asset Identifier) for the currency. - **subject** (string) - Optional - The new subject or title for the proposal. - **permlink** (string) - Optional - The new permlink associated with the proposal. - **extensions** (array) - Optional - An array of extensions to apply to the proposal update. - **type** (string) - Required - The type of extension (e.g., "update_proposal_end_date"). - **value** (object) - Required - The value associated with the extension. - **end_date** (string) - Required - The new end date for the proposal in ISO 8601 format (YYYY-MM-DDTHH:mm:ss). ### Request Example ```json { "proposal_id": "1", "creator": "your-account", "daily_pay": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "subject": "Proposal Update", "permlink": "proposal-update", "extensions": [ { "type": "update_proposal_end_date", "value": { "end_date": "2023-03-14T00:00:00" } } ] } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the broadcasted operation. #### Response Example ```json { "tx_id": "1fdce7303d535ca89b99c501113b36076586374d9ddc481519db70c94ea54fd23214b0a8353799008afa35d9f53c5bdd6b943fd132db506b6c5f26854a821dfd7e" } ``` ``` -------------------------------- ### Use Beekeeper Signer for Transaction Signing Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/beekeeper Example of using the Beekeeper provider with the Wax library to create, sign, and broadcast a transaction. This involves initializing the Wax chain, creating a Beekeeper provider instance, adding operations to a transaction, signing it with Beekeeper, and finally broadcasting it. ```javascript import { createHiveChain } from "@hiveio/wax"; import BeekeeperProvider from "@hiveio/wax-signers-beekeeper"; const chain = await createHiveChain(); const provider = BeekeeperProvider.for(myWallet, "myaccount", "active", chain); // Create a transaction using the Wax Hive chain instance const tx = await chain.createTransaction(); // Perform some operations, e.g. push the vote operation: tx.pushOperation({ vote_operation: { voter: "alice", author: "bob", permlink: "example-post", weight: 10000 } }); // Wait for the keychain to sign the transaction await provider.signTransaction(tx); // broadcast the transaction await chain.broadcast(tx); ``` -------------------------------- ### Encrypting and Transferring Hive Coins Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet demonstrates how to encrypt a transfer operation and push it into a transaction. It utilizes the `startEncrypt`, `pushOperation`, and `stopEncrypt` methods for managing the encryption process within a transaction context. The `toApi` method is used to serialize the transaction for broadcasting. ```javascript const transferEncryptionOp = { transfer_operation: { from: accountName, to: "friend", amount: chain.hiveCoins(100), memo: "This will be encrypted" } }; encryptionTx .startEncrypt(publicEncryptionSigningKey) .pushOperation(transferEncryptionOp) .stopEncrypt() .pushOperation(transferOp); encryptionTx.sign(wallet, publicPostingSigningKey); console.log(encryptionTx.toApi()); // await chain.broadcast(otherOperationsTx); ``` -------------------------------- ### Usage: Sign Transaction with HB Auth and Wax Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/hb-auth Example demonstrating how to use the HB Auth signer with the Wax library to create and sign a Hive transaction. It covers initializing the chain, creating a provider, pushing operations, signing, and broadcasting. ```typescript import { createHiveChain } from "@hiveio/wax"; import HBAuthProvider from "@hiveio/wax-signers-hb-auth"; const chain = await createHiveChain(); const provider = HBAuthProvider.for(hbAuthClient, "gtg", "posting"); // Create a transaction using the Wax Hive chain instance const tx = await chain.createTransaction(); // Perform some operations, e.g. push the vote operation: tx.pushOperation({ vote_operation: { voter: "alice", author: "bob", permlink: "example-post", weight: 10000 } }); // Wait for the keychain to sign the transaction await provider.signTransaction(tx); // broadcast the transaction await chain.broadcast(tx); ``` -------------------------------- ### Create and Sign Legacy Hive Transaction with Vote Operation (JavaScript) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet shows how to initialize the Hive chain, create a transaction with a vote operation, convert it to the legacy API format, and sign it externally using a provided digest and a wallet. It's important to note that the legacy format is deprecated and signers do not support it directly, necessitating external signing mechanisms like the Beekeeper wallet used here. ```javascript import { createHiveChain } from '@hiveio/wax'; // Initialize chain const chain = await createHiveChain(); // Create/get a wallet const { wallet, publicKey1 } = globalThis.snippetsBeekeeperData; // Create a transaction const tx = await chain.createTransaction(); // Declare example operation const operation = { vote_operation: { voter: "voter", author: "author", permlink: "test-permlink", weight: 2200 } }; // Push the operation into the transaction tx.pushOperation(operation); // Convert the transaction into the Hive API-legacy form JSON before signing const legacyApiTx = tx.toLegacyApi(); console.log(legacyApiTx); // Because we want to process transction signing in legacy way, we need to sign the transaction externally, which is shown below. // We need to calculate the transaction digest first. const digest = tx.legacy_sigDigest; /* Other signers (except beekeeper) do not allow signing the digest directly, this is a beekeeper-specific feature. */ // Generate the signature based on the transction digest const signature = wallet.signDigest(publicKey1, digest); // Suplement the transaction by created signature tx.addSignature(signature); // This is JSON form ready for broadcasting or passing to third-party service. const txApiForm = tx.toLegacyApi(); console.log(txApiForm); ``` -------------------------------- ### Update Proposal Operation with End Date Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/operations/update-proposal Illustrates how to update a Hive blockchain proposal and include an end date for the proposal. This example extends the basic update by adding an `endDate` parameter, which can be a date string or a timestamp. The process involves initializing the chain and transaction, creating the `UpdateProposalOperation` with the end date, and adding it to the transaction. The result is the unsigned transaction. ```typescript import { createHiveChain, UpdateProposalOperation } from '@hiveio/wax'; // Initialize hive chain interface const chain = await createHiveChain(); // Initialize a transaction object const tx = await chain.createTransaction(); const proposalId = 1; const creator = "your-account"; const dailyPay = chain.hbdCoins(100); // 100.000 HBD const subject = "Proposal Update"; const permlink = "proposal-update"; const endDate = '2023-03-14' // You can also give end date as a timestamp, eg. 1678917600000 tx.pushOperation(new UpdateProposalOperation({ proposalId, creator, dailyPay, subject, permlink, endDate })); /* Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet** */ console.log(tx.transaction); ``` -------------------------------- ### Updating Hive Account Authorities Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This code illustrates how to update an account's authorities using `AccountAuthorityUpdateOperation`. It demonstrates checking for existing authorities, adding new ones with specific weights, setting the memo key, and iterating through different authority levels. The changes are then applied to a transaction and logged. ```javascript const accountUpdateTx = await chain.createTransaction(); const accountAuthorityUpdateOp = await AccountAuthorityUpdateOperation.createFor( chain, "gtg" ); const hasGandalfAuth = accountAuthorityUpdateOp.role("active").has("gandalf"); console.log("Has Gandalf Auth:", hasGandalfAuth); accountAuthorityUpdateOp.role("active").add("frodo", 2); accountAuthorityUpdateOp.role("memo").set( "STM8GC13uCZbP44HzMLV6zPZGwVQ8Nt4Kji8PapsPiNq1BK153XTX" ); console.log("Current account authority:") for(const role of accountAuthorityUpdateOp.roles("hive")) console.log(role.level, ":", role.value); accountUpdateTx.pushOperation(accountAuthorityUpdateOp); accountUpdateTx.sign(wallet, publicActiveSigningKey); console.log(accountUpdateTx.toApi()); // await chain.broadcast(otherOperationsTx); ``` -------------------------------- ### Hive Custom JSON Operations for Social and RC Management Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Demonstrates various 'custom_json_operation' uses on Hive, including following/muting blogs, reblogging posts, delegating Resource Credits (RC), subscribing to communities, and flagging posts within communities. Each operation requires a specific 'id' and a JSON payload detailing the action, involved accounts, and parameters. ```json { "ref_block_num": 32101, "ref_block_prefix": 2985086707, "expiration": "2024-07-02T15:56:29", "operations": [ { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"follow\",{\"follower\":\"your-account\",\"following\":\"blog-to-follow\",\"what\":[\"blog\"]}]" } }, { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"follow\",{\"follower\":\"your-account\",\"following\":\"blog-to-mute\",\"what\":[\"ignore\"]}]" } }, { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"reblog\",{\"account\":\"your-account\",\"author\":\"to-reblog\",\"permlink\":\"post-permlink\"}]" } }, { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "rc", "json": "[\"delegate_rc\",{\"from\":\"your-account\",\"delegatees\":[\"friend\"],\"max_rc\":\"1000\",\"extensions\":[]}]" } }, { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "community", "json": "[\"subscribe\",{\"community\":\"communityName\"}]" } }, { "type": "custom_json_operation", "value": { "required_posting_auths": [ "your-account" ], "id": "community", "json": "[\"flagPost\",{\"community\":\"community-name\",\"account\":\"author-account\",\"permlink\":\"post-permlink\",\"notes\":\"violation notes\"}]" } } ], "signatures": [ "1fdce7303d535ca89b99c501113b36076586374d9ddc481519db70c94ea54fd23214b0a8353799008afa35d9f53c5bdd6b943fd132db506b6c5f26854a821dfd7e" ] } ``` -------------------------------- ### Hive Recurrent Transfer and Proposal Operations Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Demonstrates creating a recurrent transfer and updating a proposal on the Hive blockchain. This involves specifying sender, receiver, amount, memo, recurrence, and execution details for transfers, and proposal details like ID, daily pay, subject, permlink, and end date for proposal updates. Dependencies include the 'recurrent_transfer_operation' and 'update_proposal_operation' types. ```json { "ref_block_num": 32101, "ref_block_prefix": 2985086707, "expiration": "2024-07-02T15:56:29", "operations": [ { "type": "recurrent_transfer_operation", "value": { "from": "your-account", "to": "friend", "amount": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "memo": "Daily pay", "recurrence": 24, "executions": 30 } }, { "type": "update_proposal_operation", "value": { "proposal_id": "1", "creator": "your-account", "daily_pay": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "subject": "Proposal Update", "permlink": "proposal-update", "extensions": [ { "type": "update_proposal_end_date", "value": { "end_date": "2023-03-14T00:00:00" } } ] } } ], "signatures": [ "1fb7cb30e685afdf928d14a8a04a0e8d75511137d72db7e5be0a79d633b54795ee097f2b4cacbfbff1b0f470cbed35146bd35d09ae3987cd6dcf3db0df8bca84e4" ] } ``` -------------------------------- ### Use MetaMask as a Wax Signer (JavaScript) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/signers/metamask Demonstrates how to set up and use the MetaMask provider with the Wax library in JavaScript. It shows creating a Hive chain instance, initializing the MetaMask provider, constructing a transaction, signing it with MetaMask, and broadcasting it. ```javascript import { createHiveChain } from "@hiveio/wax"; import MetaMaskProvider from "@hiveio/wax-signers-metamask"; const chain = await createHiveChain(); const provider = MetaMaskProvider.for(0); // Create a transaction using the Wax Hive chain instance const tx = await chain.createTransaction(); // Perform some operations, e.g. push the vote operation: tx.pushOperation({ vote_operation: { voter: "alice", author: "bob", permlink: "example-post", weight: 10000 } }); // Wait for the keychain to sign the transaction await provider.signTransaction(tx); // broadcast the transaction await chain.broadcast(tx); ``` -------------------------------- ### Legacy Transfer Transaction Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This example shows a legacy Hive transaction format for transferring funds. It uses a string representation for the amount and includes a memo field. ```json { "ref_block_num": 32100, "ref_block_prefix": 27252558, "expiration": "2024-07-02T15:56:28", "operations": [ [ "transfer", { "from": "your-account", "to": "friend", "amount": "0.100 HIVE", "memo": "My transfer operation" } ] ], "extensions": [], "signatures": [ "1f5e2496ba8f6d2bcace6f6d244d8d130b053dfc5c17c4474b77a6110d8650451512dc6242cf5149bb2e6ae58b279378af230d71fbe62e2c1685912f4789b68a78" ] } ``` -------------------------------- ### Pushing Simple Operation in JavaScript Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/working-with-transaction/pushing-simple-operation Demonstrates how to initialize the Hive chain, create a transaction object, push a vote operation, and retrieve the built transaction using the Wax library in JavaScript. It requires the '@hiveio/wax' package. ```javascript import { createHiveChain } from '@hiveio/wax'; // Initialize hive chain interface const chain = await createHiveChain(); // Initialize a transaction object const tx = await chain.createTransaction(); // Declare example operation const operation = { vote_operation: { voter: "voter", author: "test-author", permlink: "test-permlink", weight: 2200 } }; // Push operation into the transction tx.pushOperation(operation); /* Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet** */ const builtTx = tx.transaction; console.log(builtTx.operations); ``` -------------------------------- ### Wax Initialization with Custom Options in JavaScript Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/config/init-general Initializes the Hive Chain with custom configuration options. This allows specifying the chain ID, API endpoint, REST API endpoint, and API timeout for tailored performance and network settings. ```javascript import { createHiveChain, IWaxOptionsChain } from '@hiveio/wax'; // Define custom options const customOptions: IWaxOptionsChain = { // Example custom chain ID: chainId: 'f875a0b000000000000000000000000000000000000000000000000000000000', // Example custom API endpoint: apiEndpoint: 'https://hive.custom.endpoint', // Example custom REST API endpoint: restApiEndpoint: 'https://rest.api.custom.endpoint', // Disable API timeout: apiTimeout: 0 }; // Initialize Hive Chain with custom options const chain = await createHiveChain(customOptions); ``` -------------------------------- ### POST /operations/transfer Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Executes a recurrent transfer operation on the blockchain. This allows for scheduled or recurring transfers between accounts. ```APIDOC ## POST /operations/transfer ### Description Executes a recurrent transfer operation on the blockchain. This allows for scheduled or recurring transfers between accounts. ### Method POST ### Endpoint /operations/transfer ### Parameters #### Request Body - **from** (string) - Required - The account name from which the transfer will be made. - **to** (string) - Required - The account name to which the transfer will be made. - **amount** (object) - Required - The amount to transfer. - **amount** (string) - Required - The numerical value of the amount. - **precision** (integer) - Required - The number of decimal places for the amount. - **nai** (string) - Required - The NAI (Numeric Asset Identifier) for the currency. - **memo** (string) - Optional - A memo or description for the transfer. - **recurrence** (integer) - Required - The recurrence interval in hours (e.g., 24 for daily). - **executions** (integer) - Required - The total number of executions for this recurrent transfer. ### Request Example ```json { "from": "your-account", "to": "friend", "amount": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "memo": "Daily pay", "recurrence": 24, "executions": 30 } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the broadcasted operation. #### Response Example ```json { "tx_id": "1fb7cb30e685afdf928d14a8a04a0e8d75511137d72db7e5be0a79d633b54795ee097f2b4cacbfbff1b0f470cbed35146bd35d09ae3987cd6dcf3db0df8bca84e4" } ``` ``` -------------------------------- ### Encrypted Transfer Transaction Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage This snippet illustrates an encrypted transfer transaction on Hive. The memo field contains an encrypted payload, indicated by the '#' prefix. ```json { "ref_block_num": 32100, "ref_block_prefix": 27252558, "expiration": "2024-07-02T15:56:28", "operations": [ { "type": "transfer_operation", "value": { "from": "your-account", "to": "friend", "amount": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "memo": "#4MWxEsc6QMPu5ifjW1mNpJh6Rx4Li4kaJVxEvNFWysAsggDSLNF6ZEdauVEuompzPXuMuZ4tfTtAadcYXHAXH5ASVCRapttKgx7xEn1S4dydFrM7Uc8jpMmdJ4HDxnhCELxQrxX4iqoFhYaVdYPVq3A8" } }, { "type": "transfer_operation", "value": { "from": "your-account", "to": "friend", "amount": { "amount": "100", "precision": 3, "nai": "@@000000021" }, "memo": "My transfer operation" } } ], "signatures": [ "20768549f9e17688287c6e511a1efa170834dd5ef0662e737de47a874876b83a4812a2f38d1386c1d2ab2ae055282f1ada76646434ad87377a78988c70de36a7ed" ] } ``` -------------------------------- ### POST /operations/witness_set_properties Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Sets properties for a witness account on the blockchain. This includes parameters like account creation fee, HBD interest rate, and witness key. ```APIDOC ## POST /operations/witness_set_properties ### Description Sets properties for a witness account on the blockchain. This includes parameters like account creation fee, HBD interest rate, and witness key. ### Method POST ### Endpoint /operations/witness_set_properties ### Parameters #### Request Body - **owner** (string) - Required - The account name of the witness. - **props** (array) - Required - An array of property key-value pairs to set. - **key** (string) - Required - The name of the property (e.g., "account_creation_fee"). - **value** (string) - Required - The value to set for the property. ### Request Example ```json { "owner": "your-account", "props": [ [ "account_creation_fee", "307500000000000003535445454d0000" ], [ "hbd_interest_rate", "ee02" ], [ "key", "03d61d6fa3124160f86e1f870328e4ee1c4956529f3e001a3ce466d192bd4e07ab" ], [ "maximum_block_size", "00000100" ], [ "url", "1368747470733a2f2f6578616d706c652e636f6d" ] ] } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the broadcasted operation. #### Response Example ```json { "tx_id": "1fb7cb30e685afdf928d14a8a04a0e8d75511137d72db7e5be0a79d633b54795ee097f2b4cacbfbff1b0f470cbed35146bd35d09ae3987cd6dcf3db0df8bca84e4" } ``` ``` -------------------------------- ### Handle Exceeding Precision for Asset Fractional Parts (Python) Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/asset-manipulations/generating-assets Demonstrates how the Wax library handles exceeding the maximum fractional parts for Hive, HBD, and Vests assets. Excess fractional parts are truncated without rounding. ```python # Example of exceeding the precision limit for fractional parts: # 100123 - the rest of the fractional parts have been cut without any rounding down. # chain.hive_coins(100.123456).amount # 100123 - the rest of the fractional parts have been cut without any rounding up. # chain.hbd_coins(100.123678).amount # 100123456 - the rest of the fractional parts have just been cut. # chain.vests_coins(100.123456789).amount ``` -------------------------------- ### POST /operations/custom_json Source: https://hive.pages.syncad.com/wax-doc/default/interfaces/transaction/example-usage Executes a custom JSON operation on the blockchain. This is a versatile endpoint for various custom actions like following users, reblogging posts, or interacting with communities. ```APIDOC ## POST /operations/custom_json ### Description Executes a custom JSON operation on the blockchain. This is a versatile endpoint for various custom actions like following users, reblogging posts, or interacting with communities. ### Method POST ### Endpoint /operations/custom_json ### Parameters #### Request Body - **required_posting_auths** (array) - Required - An array of account names that must authorize the operation. - (string) - Account name. - **id** (string) - Required - The identifier for the custom JSON operation (e.g., "follow", "rc", "community"). - **json** (string) - Required - The JSON payload for the custom operation, as a string. ### Request Examples **Follow User:** ```json { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"follow\",{\"follower\":\"your-account\",\"following\":\"blog-to-follow\",\"what\":[\"blog\"]}]" } ``` **Mute User:** ```json { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"follow\",{\"follower\":\"your-account\",\"following\":\"blog-to-mute\",\"what\":[\"ignore\"]}]" } ``` **Reblog Post:** ```json { "required_posting_auths": [ "your-account" ], "id": "follow", "json": "[\"reblog\",{\"account\":\"your-account\",\"author\":\"to-reblog\",\"permlink\":\"post-permlink\"}]" } ``` **Delegate Resource Credits (RC):** ```json { "required_posting_auths": [ "your-account" ], "id": "rc", "json": "[\"delegate_rc\",{\"from\":\"your-account\",\"delegatees\":[\"friend\"],\"max_rc\":\"1000\",\"extensions\":[]}]" } ``` **Subscribe to Community:** ```json { "required_posting_auths": [ "your-account" ], "id": "community", "json": "[\"subscribe\",{\"community\":\"communityName\"}]" } ``` **Flag Post in Community:** ```json { "required_posting_auths": [ "your-account" ], "id": "community", "json": "[\"flagPost\",{\"community\":\"community-name\",\"account\":\"author-account\",\"permlink\":\"post-permlink\",\"notes\":\"violation notes\"}]" } ``` ### Response #### Success Response (200) - **tx_id** (string) - The transaction ID of the broadcasted operation. #### Response Example ```json { "tx_id": "1fdce7303d535ca89b99c501113b36076586374d9ddc481519db70c94ea54fd23214b0a8353799008afa35d9f53c5bdd6b943fd132db506b6c5f26854a821dfd7e" } ``` ```