### Starting Arweave Gateway with Main Domain (Bash) Source: https://github.com/arweaveteam/arweave/blob/master/doc/gateway_setup_guide.md This command starts the Arweave server in gateway mode. It specifies the main domain name that the gateway will serve content from using the `gateway` flag. ```Bash ./arweave-server gateway gateway.example ``` -------------------------------- ### Starting Arweave Gateway with Custom Domains (Bash) Source: https://github.com/arweaveteam/arweave/blob/master/doc/gateway_setup_guide.md This command starts the Arweave server as a gateway, specifying the main domain with the `gateway` flag and additional custom domains using repeated `custom_domain` flags. This allows the gateway to serve content for transactions linked to these specific custom domains. ```Bash ./arweave-server gateway gateway.example custom_domain custom1.domain.example custom_domain custom2.domain.example ``` -------------------------------- ### Installing go-ipfs from archive - Shell Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Extracts the go-ipfs archive, changes into the directory, and runs the installation script. The script typically installs the binary to /usr/local/bin. Requires downloading the go-ipfs tarball first. ```Shell tar xvfz go-ipfs.tar.gz cd go-ipfs ./install.sh ``` -------------------------------- ### Starting Arweave server with IPFS pinning (Cmd Arg) - Shell Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Starts the `arweave-server` process as a peer and simultaneously enables the IPFS pinning functionality by including the `ipfs_pin` argument. This is an alternative to starting pinning from the Erlang shell. Requires the IPFS daemon to be running separately. ```Shell arweave-server peer ... ipfs_pin ``` -------------------------------- ### Configuring Arweave Gateway Main Domain (JSON) Source: https://github.com/arweaveteam/arweave/blob/master/doc/gateway_setup_guide.md This JSON snippet shows how to configure the main gateway domain name within the Arweave server's configuration file using the "gateway" field. The node will run in gateway mode and serve content from the specified domain. ```JSON { // ... "gateway": "gateway.example" } ``` -------------------------------- ### Configuring Arweave Gateway Custom Domains (JSON) Source: https://github.com/arweaveteam/arweave/blob/master/doc/gateway_setup_guide.md This JSON snippet shows how to configure the main gateway domain and a list of custom domains within the Arweave server's configuration file. The "gateway" field sets the main domain, and the "custom_domains" array lists additional domains for serving transactions. ```JSON { // ... "gateway": "gateway.example", "custom_domains": [ "custom1.domain.example", "custom2.domain.example" ] } ``` -------------------------------- ### Marking the Start of Erlang Module Tests Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet shows the specific comment format required in the Arweave Erlang style guide to indicate the beginning of the test definition section within a module file. This comment should be the last thing before the actual test cases are defined. ```Erlang % Tests: {module name} ``` -------------------------------- ### Example GET Peers Request - Javascript (XMLHttpRequest) Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This JavaScript example demonstrates how to use XMLHttpRequest to make a GET request to the /peers endpoint to retrieve the list of connected peers from an Arweave node. ```javascript var node = 'http://127.0.0.1:1984'; var path = '/peers'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Starting the IPFS daemon - Shell Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Starts the IPFS daemon, which runs the IPFS node in the background. This daemon must be running for the Arweave `ipfs_pin` functionality to interact with the local IPFS node. ```Shell ipfs daemon ``` -------------------------------- ### Printing User Information with ar:console in Erlang Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet demonstrates the recommended way to output information intended for the end user in the Arweave Erlang project using the ar:console/1-2 functions. It shows examples of printing formatted strings and structured data lists, which are also written to the log file. ```Erlang ar:console("Started mining on block height ~B", [Height]), ``` ```Erlang ar:console( [ node_joined_successfully, {height, NewB#block.height} ] ), ``` -------------------------------- ### Example GET Transactions Request - Javascript (XMLHttpRequest) Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This JavaScript example demonstrates how to use XMLHttpRequest to make a GET request to the /wallet/[wallet_address]/txs/[earliest_tx] endpoint to retrieve transactions made by a specific wallet. ```javascript var node = 'http://127.0.0.1:1984'; var path = '/wallet/VukPk7P3qXAS2Q76ejTwC6Y_U_bMl_z6mgLvgSUJIzE/txs/bUfaJN-KKS1LRh_DlJv4ff1gmdbHP4io-J9x7cLY5is'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Installing Dependencies on Ubuntu (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Installs required system dependencies like Erlang, OpenSSL headers, GMP headers, SQLite3 headers, Make, CMake, GCC, and G++ on Ubuntu using the `apt` package manager. This is necessary for building the Arweave server from source. ```sh sudo apt install erlang libssl-dev libgmp-dev libsqlite3-dev make cmake gcc g++ ``` -------------------------------- ### Naming Erlang Variables Descriptively Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet provides "Bad" and "Good" examples to illustrate the importance of using descriptive variable names in Erlang code according to the Arweave style guide. It shows how meaningful variable names improve code readability without needing extra comments. ```Erlang %% Bad variables sign_data(X, Y) -> {A, B} = X, sign(A, Y). %% Good variables sign_data(Keypair, Data) -> {Priv, Pub} = Keypair, sign(Priv, Data). ``` -------------------------------- ### Initializing IPFS node configuration - Shell Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Runs the `ipfs init` command to create the local IPFS repository (~/.ipfs), which contains configuration files and data. This must be done once before starting the IPFS daemon. ```Shell ipfs init ``` -------------------------------- ### Example GET Peers Response Format - Javascript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This snippet shows the expected JSON array format returned by the GET /peers endpoint. It contains a list of IP addresses (with optional ports) representing the peers connected to the contacted node. ```javascript [ "127.0.0.1:1985", "127.0.0.1.:1986" ] ``` -------------------------------- ### Starting Arweave server as peer - Shell Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Runs the `arweave-server` command with the `peer` argument, initiating the Arweave node in peer mode. This command is a prerequisite for interacting with the server via the Erlang shell. ```Shell arweave-server peer ... ``` -------------------------------- ### Logging Messages with ar:info/warn/err in Erlang Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet illustrates the usage of the ar module's logging functions (ar:info, ar:warn, ar:err) for generating log entries in the Arweave Erlang project. It shows examples for warning and error messages, noting that error messages are also displayed in the console. ```Erlang ar:warn("Could not retrieve current block. Will retry in ~B seconds", [?REJOIN_TIMEOUT]), ``` ```Erlang ar:err( [ node_not_joining, {reason, cannot_get_full_block_from_peer}, {received_instead, NewB} ] ), ``` -------------------------------- ### Starting Arweave IPFS pinning (Erlang Console) - Erlang Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Executes the `app_ipfs:start_pinning()` function in the Erlang console connected to the running Arweave server process. This enables the server to listen for and pin IPFS data from transactions. Requires the Arweave server to be running and an attached Erlang shell. ```Erlang app_ipfs:start_pinning(). ``` -------------------------------- ### Example GET Transaction Response Format - Javascript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This snippet shows the expected JSON format returned by the GET /wallet/[wallet_address]/txs/[earliest_tx] and GET /wallet/[wallet_address]/deposits/[earliest_deposit] endpoints. It is a JSON array containing Base64url encoded transaction identifiers. ```javascript ["bUfaJN-KKS1LRh_DlJv4ff1gmdbHP4io-J9x7cLY5is","b23...xg"] ``` -------------------------------- ### Starting New Arweave Localnet (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Initializes and starts a new Arweave local network using the `bin/start-localnet` script. It specifies the data directory, optionally sets a mining address, configures storage, and enables mining to create the genesis block and subsequent blocks in the local weave. ```sh $ ./bin/start-localnet init data_dir mining_addr \ storage_module 0, mine ``` -------------------------------- ### Formatting Function Arguments Erlang Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet demonstrates the recommended style for formatting function arguments in Erlang when they exceed the line length limit or include inline functions. Arguments are placed on separate lines for improved readability. It shows both a non-compliant ("Bad") and a compliant ("Better") example using lists:foldl. ```Erlang %% Bad example() -> TotalTime = lists:foldl(fun(X, Acc) -> X + Acc end, 0, [12, 15, 8, 21, 35, 33, 14]), ... %% Better example() -> TotalTime = lists:foldl( fun(X, Acc) -> X + Acc end, 0, [12, 15, 8, 21, 35, 33, 14] ), ... ``` -------------------------------- ### Naming Erlang Atoms with Lowercase and Underscores Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet provides examples of "Bad" and "Good" atom names according to the Arweave Erlang style guide. It shows the preference for using lowercase letters and underscores to separate words in atoms for better readability and consistency. ```Erlang %% Bad atoms 'iAtom' 'block not found' %% Good atoms unavailable block_not_found ``` -------------------------------- ### Joining Public Arweave Testnet (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Starts the Arweave node using the `bin/start` script and connects it to a predefined list of public testnet peer nodes. This command allows the node to synchronize with and participate in the Arweave testnet network. ```sh ./bin/start peer testnet-1.arweave.xyz peer testnet-2.arweave.xyz peer testnet-3.arweave.xyz ``` -------------------------------- ### Avoiding Excessive Internal Comments in Erlang Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet provides a "Bad" and "Good" example to highlight the principle of minimizing comments within Erlang function bodies. The "Good" example demonstrates how clear code, variable names, and deconstruction can reduce the need for comments explaining obvious steps, focusing instead on overall purpose (documented externally). ```Erlang %% Bad sign_verify_test(Keypair) -> % Deconstructs keypair into two separate terms, Pub and Priv. {Priv, Pub} = Keypair, % Generates an integer between 1 and 100 to sign and then verify. Data = floor(rand:uniform() * 100), % Sign the data generated above. SignedData = sign(Priv, Data), % Verify the signed data. verify(Pub, SignedData). %% Good sign_verify_test({Priv, Pub}) -> Data = floor(rand:uniform() * 100), SignedData = sign(Priv, Data), verify(Pub, SignedData). ``` -------------------------------- ### Deconstructing Erlang Function Arguments in Header Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet illustrates the Arweave Erlang style guide's preference for deconstructing function arguments directly in the function header rather than the body. The "Good" example shows how this makes the required argument structure explicit and improves pattern matching clarity. ```Erlang %% Bad server(State, Keypair) -> Keypair = {Priv, Pub}, State#state { peers = Peers, heard = HeardMsg, ignored = IgnoredMsg }, ... %% Good server(State#state { peers = Peers, heard = HeardMsg, ignored = IgnoredMsg }, {Priv, Pub}) -> ... ``` -------------------------------- ### Configuring Arweave Service in NixOS Source: https://github.com/arweaveteam/arweave/blob/master/nix/README.md Provides an example configuration snippet for 'configuration.nix' in NixOS. It shows how to enable the 'services.arweave' option to run the Arweave node as a systemd service and configure basic settings like specifying initial peer addresses. ```Nix { config = { services.arweave = { enable = true; peer = [ "188.166.200.45" "188.166.192.169" "163.47.11.64" ]; # see more options below }; }; } ``` -------------------------------- ### Example POST Transaction Request - Javascript (XMLHttpRequest) Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This JavaScript example demonstrates how to use XMLHttpRequest to make a POST request to the /tx endpoint with a transaction object in the request body to submit a transaction to the network. ```javascript var node = 'http://127.0.0.1:1984'; var path = '/tx'; var url = node + path; var xhr = new XMLHttpRequest(); var post = { "id": "VvNF3aLS28MXD_o4Lv0lF9_WcxMibFOp166qDqC1Hlw", "last_tx": "bUfaJN-KKS1LRh_DlJv4ff1gmdbHP4io-J9x7cLY5is", "owner": "1Q7RfP...J2x0xc", "tags": [], "target": "", "quantity": "0", "data": "3DduMPkwLkE0LjIxM9o", "reward": "1966476441", "signature": "RwBICn...Rxqi54" }; xhr.open('POST', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(post); ``` -------------------------------- ### Example Arweave Path Manifest JSON Source: https://github.com/arweaveteam/arweave/blob/master/doc/path-manifest-schema.md This JSON object provides a concrete example of an Arweave path manifest adhering to the specified schema. It demonstrates the structure including the manifest type, version, an index path specifying the default file (`index.html`), and a `paths` object mapping various subpaths (`index.html`, `js/style.css`, etc.) to their corresponding Arweave transaction IDs. ```json { "manifest": "arweave/paths", "version": "0.1.0", "index": { "path": "index.html" }, "paths": { "index.html": { "id": "cG7Hdi_iTQPoEYgQJFqJ8NMpN4KoZ-vH_j7pG4iP7NI" }, "js/style.css": { "id": "fZ4d7bkCAUiXSfo3zFsPiQvpLVKVtXUKB6kiLNt2XVQ" }, "css/style.css": { "id": "fZ4d7bkCAUiXSfo3zFsPiQvpLVKVtXUKB6kiLNt2XVQ" }, "css/mobile.css": { "id": "fZ4d7bkCAUiXSfo3zFsPiQvpLVKVtXUKB6kiLNt2XVQ" }, "assets/img/logo.png": { "id": "QYWh-QsozsYu2wor0ZygI5Zoa_fRYFc8_X1RkYmw_fU" }, "assets/img/icon.png": { "id": "0543SMRGYuGKTaqLzmpOyK4AxAB96Fra2guHzYxjRGo" } } } ``` -------------------------------- ### Specifying Local Blacklist Files (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/doc/transaction_blacklists.md Shows how to start an Arweave node and configure multiple transaction blacklist files using the `transaction_blacklist` command-line argument. Each argument specifies a path to a file containing transaction identifiers to blacklist. ```Shell ./bin/start transaction_blacklist my_tx_blacklist.txt transaction_blacklist my_other_tx_blacklist.txt ... ``` -------------------------------- ### Naming Erlang Functions Concisely and Descriptively Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet contrasts "Bad" verbose function names with "Good" concise ones in Erlang, illustrating the style guide's preference. It shows how function names should be descriptive enough for their high-level purpose while remaining short, often relying on the module name for additional context. ```Erlang %% Bad function names ar_tx:generate_data_segment_for_signing(TX). ar_util:pretty_print_internal_ip_representation(IPAddr). ar_retarget:is_current_block_retarget_block(Block). %% Good function names ar_tx:to_binary(TX). ar_block:generate_block_from_shadow(BShadow). ar_serialize:block_to_json_struct(Block). ``` -------------------------------- ### Avoiding Deeply Nested Code in Erlang with Case Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet compares a "Bad" deeply nested Erlang code example with a "Better" version using multiple function clauses and a single-level case statement. It demonstrates how to avoid complex nesting by structuring code with multiple function headers and guards for clarity and maintainability. ```Erlang %% Bad contains_data_tx([]) -> false; contains_data_tx(TXList) -> [TX|Rest] = TXList, case is_record(TX, tx) of true -> case byte_size(TX#tx.data) > 0 of true -> true; false -> contains_data_tx(Rest) end; false -> error_not_tx. end. %% Better contains_data_tx([]) -> false; contains_data_tx([TX|Rest]) when is_record(TX, tx) -> case byte_size(TX#tx.data) > 0 of true -> true; false -> contains_data_tx(Rest) end; contains_data_tx(_) -> error_not_tx. ``` -------------------------------- ### Starting Arweave Erlang Shell (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Launches an interactive Erlang shell configured to interact with the running Arweave node environment. This allows developers to inspect the node's state, run commands, and debug issues directly within the Erlang runtime. ```sh $ bin/shell ``` -------------------------------- ### Installing Dependencies on MacOS (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Installs required dependencies like GMP, OpenSSL 1.1, Erlang 24, CMake, and pkg-config on MacOS using the Homebrew package manager. These packages are needed for building the Arweave server from source on MacOS, particularly for VDF servers. ```sh brew install gmp openssl@1.1 erlang@24 cmake pkg-config ``` -------------------------------- ### Formatting Erlang List Deconstruction Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet shows the required formatting for deconstructing lists into head and tail in Erlang according to the Arweave style guide. It demonstrates the "Good" practice of placing spaces on either side of the | character for clarity. ```Erlang %% Bad [Head|Tail] %% Good [Head | Tail] ``` -------------------------------- ### Example Response: Post Unsigned Transaction (JSON) Source: https://github.com/arweaveteam/arweave/blob/master/http_post_unsigned_tx_docs.md This is an example of the JSON response body returned by the `POST /unsigned_tx` endpoint after successfully accepting and posting an unsigned transaction. It contains the transaction's unique `id`. ```JSON {"id": "F8ITA-zojpRtUNnULnKasJCHL46rcqQBpSyqBekWnF30S7GCd58LcIcOXhYnYL6U"} ``` -------------------------------- ### Local Blacklist File Format (Text) Source: https://github.com/arweaveteam/arweave/blob/master/doc/transaction_blacklists.md Provides an example of the content expected in a local transaction blacklist file. Each line must contain a single Base64 encoded transaction identifier that the node should not store. ```Text K76dxpFF7MJXa3SPG8XnrgXxf05eAz7jz2Vue1Bdw1M cPm9Et8pNCh1Boo1aJ7eLGxywhI06O7DQm84V1orBsw xiQYsaUMtlIq9DvTyucB4gu0BFC-qnFRIDclLv8wUT8 ``` -------------------------------- ### Getting Current Block via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves a JSON array representing the contents of the network's current block (the head) from an Arweave node using an XMLHttpRequest GET request to `/current_block`. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/current_block'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Getting Arweave IPFS server state report - Erlang Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Calls the `report/1` function from the `app_ipfs` module to retrieve the current state of the IPFS pinning server. It can be called with the atom `app_ipfs` or the process ID (`IPFSPid`) of the running process. Provides details like PIDs, wallet info, and IPFS identity. ```Erlang app_ipfs:report(app_ipfs). app_ipfs:report(IPFSPid). ``` -------------------------------- ### Documenting Erlang Module Header Structure Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet illustrates the standard structure for an Erlang module header within the Arweave project. It includes the module name declaration, -export directives listing functions available externally, -include directives for necessary header files, and a mandatory %%% prefixed comment describing the module's overall purpose. ```Erlang %% Example: head of ar_serialize. -module(ar_serialize). -export([full_block_to_json_struct/1, block_to_json_struct/1, ...]). -export([tx_to_json_struct/1, json_struct_to_tx/1]). -export([wallet_list_to_json_struct/1, block_index_to_json_struct/1, ...]). -export([jsonify/1, dejsonify/1]). -export([query_to_json_struct/1, json_struct_to_query/1]). -include("ar.hrl"). -include_lib("eunit/include/eunit.hrl"). %%% Module containing serialisation/deserialisation utility functions for use in the HTTP server. ``` -------------------------------- ### Getting Full Transaction via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Fetches a complete JSON transaction record from an Arweave node using its base64url encoded ID via an XMLHttpRequest GET request to `/tx/[transaction_id]`. Requires the transaction ID as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/tx/VvNF3aLS28MXD_o4Lv0lF9_WcxMibFOp166qDqC1Hlw'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Documenting Erlang Record Fields Inline Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet demonstrates the required style for documenting fields within an Erlang record definition. It shows how each field should have an inline comment prefixed with a single % character, providing a concise description of the field's purpose. ```Erlang -record(tx, { id = <<>>, % TX UID (Hash of signature) last_tx = <<>>, % Wallets last TX hash. owner = <<>>, % Public key of transaction owner. tags = [], % Indexable TX category identifiers. target = <<>>, % Wallet address of target of the tx. quantity = 0, % Amount of Winston to send data = <<>>, % Data body (if data transaction). signature = <<>>, % Transaction signature. reward = 0 % Transaction mining reward. }). ``` -------------------------------- ### Getting Block by Height via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves a JSON array representing a block's contents based on its height from an Arweave node using an XMLHttpRequest GET request to `/block/height/[block_height]`. Requires the block height as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/block/height/1101'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Getting Wallet Balance via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Fetches the balance in winston for a wallet specified by its base64url encoded address (SHA256 hash of RSA modulus) from an Arweave node using an XMLHttpRequest GET request to `/wallet/[wallet_address]/balance`. Requires the wallet address as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/wallet/VukPk7P3qXAS2Q76ejTwC6Y_U_bMl_z6mgLvgSUJIzE/balance'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Getting Network Info via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves the current network status information from a specific Arweave node using an XMLHttpRequest GET request. It hits the `/info` endpoint and expects a JSON object with network details like version, height, blocks, and peers. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/info'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Getting Transaction Data HTML via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Fetches and decodes the data segment of a transaction body, potentially rendering it as HTML if it represents an archived website, using an XMLHttpRequest GET request to `/tx/[transaction_id]/data.html`. Requires the transaction ID as a URL parameter. ```JavaScript var node = 'http://127.0.0.0.1:1984'; var path = '/tx/B7j_bkDICQyl_y_hBM68zS6-p8-XiFCUmEBaXRroFTM/data.html' var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Generating Wallet Response (JSON) Source: https://github.com/arweaveteam/arweave/blob/master/http_post_unsigned_tx_docs.md This is an example of the JSON response body returned by the `POST /wallet` endpoint upon successful wallet generation. It contains the `wallet_access_code` required for submitting unsigned transactions later. ```JSON {"wallet_access_code":"UEhkVh0LBqfIj60-EB-yaDSrMpR2_EytWrY0bGJc_AZaiITJ4PrzRZ_xaEH5KBD4"} ``` -------------------------------- ### Running Arweave Server in Development Mode (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Starts the Arweave server executable in development mode, connecting to a predefined list of mainnet peer nodes to synchronize with the network. This command is used to run a node configured for development purposes. ```sh ./arweave-server \ peer ams-1.eu-central-1.arweave.xyz \ peer fra-1.eu-central-2.arweave.xyz \ peer sgp-1.ap-central-2.arweave.xyz \ peer blr-1.ap-central-1.arweave.xyz \ peer sfo-1.na-west-1.arweave.xyz ``` -------------------------------- ### Getting Estimated Transaction Price via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Requests the estimated cost in winston for a transaction of a specified byte size from an Arweave node using an XMLHttpRequest GET request to `/price/[byte_size]`. The estimate is pessimistic to account for potential difficulty changes and requires the byte size as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/price/2048'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Formatting Erlang Tuples with Spaces Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet illustrates the required formatting style for Erlang tuples in the Arweave project. It shows the "Good" practice of including a space between each comma-separated element during both construction and deconstruction for improved readability, contrasting it with the "Bad" compressed style. ```Erlang %% Bad { one,two,three, A, B, C} %% Good {one, two, three, A, B, C} ``` -------------------------------- ### Exporting Minimal Erlang Functions Explicitly Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet contrasts the "Bad" practice of using -compile(export_all) with the "Good" practice of explicitly listing exported functions using -export([...]) in Erlang. It emphasizes exporting only the minimal required interface for a module. ```Erlang %% Bad function exporting -compile(export_all). %% Good function exporting -export([sign/2, verify/3]). -export([to_address/1]). ``` -------------------------------- ### Getting Block by ID via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves a JSON array representing a block's contents based on its base64url encoded independent hash ID from an Arweave node using an XMLHttpRequest GET request to `/block/hash/[block_id]`. Requires the block ID as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/block/hash/oyxTcYAgbbNoFyDz8hqs7KCJHI4qb4VdER9Jotbs';//Use \"indep_hash\" above,not hash var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Example POST Transaction Data Parameter Structure - Javascript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md This snippet illustrates the expected JSON structure for the request body when posting a transaction to the /tx endpoint using the POST method. It defines fields like last_tx, owner, target, quantity, data, reward, and signature. ```javascript { "last_tx": "", // Base64 encoded ID of the last transaction made by this wallet. Empty if this is the first transaction. "owner": "", // The public key making this transaction. "target": "", // Base64 encoded SHA256 hash of recipient's public key. Empty for data transactions. "quantity": "", // Decimal string representation of the amount of sent AR in winston. Empty for data transactions. "data": "", // The Base64 encoded data being store in the transaction. Empty for transfer transactions. "reward": "", // Decimal string representation of the mining reward AR amount in winston. "signature": "" // Base64 encoded signature of the transaction } ``` -------------------------------- ### Getting Transaction Field via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves a specific data field (like `last_tx`, `owner`, etc.) for a given transaction ID from an Arweave node using an XMLHttpRequest GET request to `/tx/[transaction_id]/[field]`. Requires both the transaction ID and the field name as URL parameters. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/tx/VvNF3aLS28MXD_o4Lv0lF9_WcxMibFOp166qDqC1Hlw/last_tx'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Getting Last Transaction ID via HTTP - JavaScript Source: https://github.com/arweaveteam/arweave/blob/master/http_iface_docs.md Retrieves the ID of the most recent transaction associated with a wallet address (base64 encoded SHA256 hash of public key) from an Arweave node using an XMLHttpRequest GET request to `/wallet/[wallet_address]/last_tx`. Requires the wallet address as a URL parameter. ```JavaScript var node = 'http://127.0.0.1:1984'; var path = '/wallet/VukPk7P3qXAS2Q76ejTwC6Y_U_bMl_z6mgLvgSUJIzE/last_tx'; var url = node + path; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { // Do something. } }; xhr.send(); ``` -------------------------------- ### Documenting Erlang Function with @doc Comment Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet demonstrates the required style for documenting Erlang functions using the %% @doc prefix. It shows a simple function count_unavailable_txs that takes a list and counts elements equal to not_found, illustrating where the documentation comment should be placed relative to the function header. ```Erlang %% Example %% @doc Takes a list containing tx records and returns the number of those 'not_found'. count_unavailable_txs(TXList) -> length([TX || TX <- TXList, TX == not_found]). ``` -------------------------------- ### Formatting Erlang Record Construction/Deconstruction Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet illustrates the required formatting style for constructing or deconstructing Erlang records in the Arweave project. It shows the "Good" practice of placing spaces on either side of the = operator when specifying field values or binding variables during record manipulation. ```Erlang %% Bad State#state {first="hello", second="world"} %% Good State#state { first = "hello", second = "world" }, ``` -------------------------------- ### Truncating Large Data in Erlang Logs Source: https://github.com/arweaveteam/arweave/blob/master/arweave_styleguide.md This snippet shows how to prevent logging excessively large data structures in Erlang logs within the Arweave project. It demonstrates using the ~P format specifier with ar:warn/2 (or other logging functions) to truncate the output of a term, specifying the desired depth. ```Erlang ar:warn("Invalid Block Hash List: ~P", [BI, 100]), ``` -------------------------------- ### Importing Arweave Module via Flakes (NixOS) Source: https://github.com/arweaveteam/arweave/blob/master/nix/README.md Shows how to define a basic NixOS system using a flake, importing the Arweave flake from GitHub and including its 'arweave' NixOS module for the 'x86_64-linux' system. This is the easiest way to enable the Arweave systemd service in NixOS via flakes. ```Nix { inputs.arweave.url = "github:ArweaveTeam/arweave"; outputs = { self, nixpkgs, arweave }: { nixosSystem = nixpkgs.lib.nixosSystem { modules = [ arweave.nixosModules."x86_64-linux".arweave ]; }; } } ``` -------------------------------- ### Accessing Arweave Package via Flakes (Non-NixOS) Source: https://github.com/arweaveteam/arweave/blob/master/nix/README.md Demonstrates how to import the 'arweave' and 'nixpkgs' flakes and access the 'arweave' package derivation within a 'let' block. This method is suitable for standalone Nix environments or other flakes where the NixOS module isn't used, allowing access to 'pkgs.arweave'. ```Nix { inputs.arweave.url = "github:ArweaveTeam/arweave"; outputs = { self, nixpkgs, arweave }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; overlays = [ arweave.overlay ]; }; in { # your flake here... # pkgs.arweave should exist } } ``` -------------------------------- ### Passing Pkgs to Arweave Module via ExtraArgs (NixOS) Source: https://github.com/arweaveteam/arweave/blob/master/nix/README.md Shows how to import the 'arweave' and 'nixpkgs' flakes and pass the 'pkgs' set to the NixOS module via the 'extraArgs' option. This is a useful technique for accessing 'pkgs.arweave' within the module context, enabling advanced configurations or overrides if needed. ```Nix { inputs.arweave.url = "github:ArweaveTeam/arweave"; outputs = { self, nixpkgs, arweave }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; extraArgs = { inherit pkgs; }; in { nixosSystem = nixpkgs.lib.nixosSystem { inherit extraArgs system; modules = [ arweave.nixosModules."${system}".arweave ]; }; }; } ``` -------------------------------- ### Arweave NixOS Service Options Schema (JSON) Source: https://github.com/arweaveteam/arweave/blob/master/nix/README.md A JSON object representing the schema and default values for the configuration options available under 'services.arweave' in the NixOS module. It lists properties like 'dataDir', 'enable', 'peer', 'user', etc., along with their default values and descriptions, serving as a reference for service configuration. ```JSON { "dataDir": { "defaultValue": "/arweave-data", "description": "Data directory path for arweave node.\n", "option": "dataDir" }, "enable": { "defaultValue": false, "description": "Whether to enable Enable arweave node as systemd service\n.", "option": "enable" }, "featuresDisable": { "defaultValue": [], "description": "List of features to disable.\n", "option": "featuresDisable" }, "group": { "defaultValue": "users", "description": "Run Arweave Node under this group.", "option": "group" }, "headerSyncJobs": { "defaultValue": 10, "description": "The pace for which to sync up with historical data.", "option": "headerSyncJobs" }, "maxDiskPoolDataRootBufferMb": { "defaultValue": 500, "description": "Max disk-pool buffer size in mb.", "option": "maxDiskPoolDataRootBufferMb" }, "maxMiners": { "defaultValue": 0, "description": "Max amount of miners to spawn, 0 means no mining will be performed.", "option": "maxMiners" }, "maxParallelBlockIndexRequests": { "defaultValue": 2, "description": "As semaphore, the max amount of parallel block index requests to perform.", "option": "maxParallelBlockIndexRequests" }, "maxParallelGetAndPackChunkRequests": { "defaultValue": 10, "description": "As semaphore, the max amount of parallel get chunk and pack requests to perform.", "option": "maxParallelGetAndPackChunkRequests" }, "maxParallelGetChunkRequests": { "defaultValue": 100, "description": "As semaphore, the max amount of parallel get chunk requests to perform.", "option": "maxParallelGetChunkRequests" }, "maxParallelGetSyncRecord": { "defaultValue": 2, "description": "As semaphore, the max amount of parallel get sync record requests to perform.", "option": "maxParallelGetSyncRecord" }, "maxParallelGetTxDataRequests": { "defaultValue": 10, "description": "As semaphore, the max amount of parallel get transaction data requests to perform.", "option": "maxParallelGetTxDataRequests" }, "maxParallelPostChunkRequests": { "defaultValue": 100, "description": "As semaphore, the max amount of parallel post chunk requests to perform.", "option": "maxParallelPostChunkRequests" }, "maxParallelWalletListRequests": { "defaultValue": 2, "description": "As semaphore, the max amount of parallel block index requests to perform.", "option": "maxParallelWalletListRequests" }, "metricsDir": { "defaultValue": "/var/lib/arweave/metrics", "description": "Directory path for node metric outputs\n", "option": "metricsDir" }, "package": { "defaultValue": "pkgs.arweave", "description": "The Arweave expression to use\n", "option": "package" }, "peer": { "defaultValue": [], "description": "List of primary node peers\n", "option": "peer" }, "transactionBlacklists": { "defaultValue": [], "description": "List of paths to textfiles containing blacklisted txids\n", "option": "transactionBlacklists" }, "transactionWhitelists": { "defaultValue": [], "description": "List of paths to textfiles containing whitelisted txids\n", "option": "transactionWhitelists" }, "user": { "defaultValue": "arweave", "description": "Run Arweave Node under this user.", "option": "user" } } ``` -------------------------------- ### Running Arweave Tests (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Executes the test suite for the Arweave server using the `bin/test` script. This script likely sets up the necessary environment, potentially involving multiple Erlang VMs, to run automated tests against the codebase. ```sh $ bin/test ``` -------------------------------- ### Creating Localnet Wallet (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Executes the `create-wallet` script located in the `bin` directory, specifying the data directory where the wallet files will be stored. This generates a new wallet for use within the local Arweave network. ```sh ./bin/create-wallet localnet_data_dir ``` -------------------------------- ### Cloning Arweave Repository (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Clones the Arweave repository from GitHub, including initializing and updating submodules using the `--recursive` flag, and then changes the current directory into the newly cloned repository. This is the first step in building from source. ```sh $ git clone --recursive https://github.com/ArweaveTeam/arweave.git $ cd arweave ``` -------------------------------- ### Building Arweave Production Tarball (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Uses the `rebar3` build tool to create a production release tarball of the Arweave server. The resulting gzipped tar archive will be located in the `_build/prod/rel/arweave/` directory, ready for deployment. ```sh $ ./rebar3 as prod tar ``` -------------------------------- ### Building Arweave Testnet Tarball (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Uses the `rebar3` build tool to create a testnet release tarball of the Arweave server. The resulting gzipped tar archive will be located in the `_build/testnet/rel/arweave/` directory, suitable for joining the testnet. ```sh $ ./rebar3 as testnet tar ``` -------------------------------- ### Creating Localnet Data Directory (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Creates a directory named `localnet_data_dir` (or any specified name) to store the blockchain data for a new local Arweave network. The `-p` flag ensures parent directories are created if they don't exist. ```sh mkdir -p localnet_data_dir ``` -------------------------------- ### Running Specific Erlang Test (Erlang) Source: https://github.com/arweaveteam/arweave/blob/master/README.md Executes a specific test function (`height_plus_one_fork_recovery_test_()`) from the `ar_fork_recovery_tests` module using the Erlang Eunit testing framework from within the Erlang shell. This allows targeted testing of individual components or scenarios. ```erlang (master@127.0.0.1)1> eunit:test(ar_fork_recovery_tests:height_plus_one_fork_recovery_test_()). ``` -------------------------------- ### Checking IPFS hash status in Arweave server - Erlang Source: https://github.com/arweaveteam/arweave/blob/master/doc/ar-ipfs-howto.md Invokes the `ipfs_hash_status/1` function of the `app_ipfs` module, passing an IPFS `Hash` as an argument. It returns a list of tuples indicating whether the hash is pinned by the local IPFS node and associated Arweave transaction IDs. ```Erlang app_ipfs:ipfs_hash_status(Hash). ``` -------------------------------- ### Specifying Remote Blacklist URL (Shell) Source: https://github.com/arweaveteam/arweave/blob/master/doc/transaction_blacklists.md Demonstrates how to configure an Arweave node to fetch a transaction blacklist from a remote HTTP endpoint. The `transaction_blacklist_url` command-line argument specifies the URL from which the node will retrieve a list of transaction identifiers. ```Shell ./bin/start transaction_blacklist_url http://blacklist.org/blacklist ```