Skip to main content
100%

hello-remote-threads.go

✓ Published0🌍 Public
Aandrewxhill
Last edited Mar 16, 2021
Created on Mar 16, 2021

This example demonstrates how to connect to Textile’s remote Hub API and create a new thread database using the Go Threads client. It generates a random Ed25519 identity for the user, authenticates with an API key and secret, then requests a user token before instantiating a thread ID and calling `NewDB`. The code uses `github.com/textileio/go-threads/api/client`, `thread.NewLibp2pIdentity`, and `common.CreateAPISigContext` to handle secure communication via gRPC with TLS credentials.

AI-generated description

Similar vizzes

Loading thumbnail…

Setup a new game of cmd-line tag!

Setup a new game of cmd-line tag! demonstrates how to orchestrate a peer-to-peer game of tag using Textile threads and command-line tools. The example shows a shell script workflow that creates a new game thread, invites peers, and manages gameplay events. The visualization centers on the `am-i-it.sh` script, which queries a Textile thread to retrieve the game's event history, traverses the thread feed in reverse chronological order, and reconstructs the chain of "tag" events by parsing JSON payloads to determine who is currently "it." The output displays a numbered list of tag events from the game's history and concludes with either a warning that you are currently it, or a directive to run from the current tag holder. The accompanying JSON schema defines the event structure for the game mechanics, showing how each event contains an event type, target peer ID, and optional extra information. The example demonstrates how Textile's thread-based data can be used to build interactive, stateful multiplayer games with a simple command-line interface.# Setup a new game of cmd-line tag! This example demonstrates how to create and manage a multiplayer game of tag using Textile threads as the underlying data structure. The visualization shows a command-line interface for setting up a game, inviting peers, and tracking the "it" status across participants through a thread of JSON events. The schema defines a game event structure with fields for event type, target peer, and extra information. The script walks through a thread's entire feed history, filtering for tag events to reconstruct the game state. As players tag each other, the script outputs a chronological play-by-play, such as "-carson- tagged you" or "you tagged -carson-", and concludes with either "Oh no, you are it!" or "Run! -carson- is it!" to indicate the current tag status. The example demonstrates how a simple game mechanic can be implemented over a peer-to-peer thread, using JSON files as the game state, and how blockchain-style hashes and addresses enable trustless multiplayer interactions.# Setup a new game of cmd-line tag! **Source:** Gist · **Author:** andrewxhill This example demonstrates how to build a multiplayer game of tag on top of Textile, a peer-to-peer protocol for encrypted, decentralized data. The workflow shows how to create a game thread with a JSON schema, invite peers, and track tag events across a distributed network. ## Key Visualization The command-line tool creates a structured game state where each action (joining, tagging, starting) is recorded as an immutable event on a thread. The JSON output reveals the underlying mechanics: - **Thread metadata** (id, name, sharing, type) defines the game's identity - **Schema node** specifies the event structure with `event`, `target`, and `extra` fields - **Block chain** tracks every action, with the head pointing to the most recent event The scripts demonstrate a complete game loop: 1. `new-game.sh` initializes a thread with a JSON schema for tag events 2. `invite` and `thread peer` manage participants 3. `tag-peer.sh` records tag events with the target's address 4. `am-i-it.sh` walks the event log to determine who is currently "it" The game mechanics are encoded as JSON events: `start`, `tag`, and metadata like `target` and `extra`. The visualization highlights the peer-to-peer nature of the game and how the Textile ThreadDB API can be used to build simple, social applications.# Setup a new game of cmd-line tag! This example demonstrates how to set up and play a game of tag using the Textile ThreadDB API, where players interact through command-line scripts that emit structured JSON events to a shared thread. ## What it shows The visualization walks through the lifecycle of a peer-to-peer game of tag built on Textile threads. It begins with creating a new game thread, which returns a detailed JSON object containing the game's ID, initiator address, schema, and initial block. From there, the example shows how to invite peers, start the game, tag other players, and check whether you are "it." The `am-i-it.sh` script is the heart of the experience. It reads the entire game history from the thread and walks through the sequence of "tag" events. Each tag event contains a `target` field identifying the next player who is "it." The script tracks the current tagger, checks whether you or another peer was tagged, and prints a running log of the game—for example, "1. -carson- tagged you" or "2. you tagged -carson-". The result is a narrative visualization of the game state from the perspective of a single player. The visualization is text-based, outputting a list of tag events and a final status message: either "Oh no, you are it!" or "Run! -carson- is it!" It uses a simple schema to structure events in a shared thread, demonstrating how Textile threads can be used to coordinate stateful, turn-based multiplayer interactions in a command-line environment. **Visualization type:** Text-based terminal game state visualization, illustrating the flow of a peer-to-peer game of tag through JSON-formatted event feeds, shell scripts, and command output.# Setup a new game of cmd-line tag! **Source:** Gist by andrewxhill This example demonstrates how to set up and play a peer-to-peer game of tag entirely through the command line, using Textile threads to coordinate game state across participants. The visualization showcases the game's mechanics through a series of shell commands and their JSON outputs, illustrating how a shared, decentralized thread tracks game events. ## How It Works The game is built on Textile threads, where each event (joining, tagging, starting) is recorded as a JSON object in a shared, encrypted thread. The core mechanics: 1. **Create a game**: A new thread is initialized with a unique name, establishing the game's schema for events (tag, start) with fields for event type, target peer, and extra info. 2. **Invite peers**: Players are invited via their textile addresses. 3. **Start the game**: The initiator sends a "start" event, becoming "it". 4. **Tag and track**: Players tag each other by writing events to the thread. The `am-i-it.sh` script traverses the thread's event history to determine the current "it" and reports the tag chain (e.g., "-carson- tagged you", "you tagged -carson-"). The game state is maintained entirely on a distributed web (Textile threads), with the tag status tracked through event history and JSON schemas. The output shows either "Oh no, you are it!" or "Run! -carson- is it!" based on the current tag holder. Title: Setup a new game of cmd-line tag! This example demonstrates how to create a new game of "cmd-line tag" using Textile threads, a peer-to-peer data framework. The visualization shows the JSON output of the `new-game.sh` script, which initializes a game thread with metadata including block count, head block information, schema definition, and peer details. The output highlights the game's mechanics, where players can tag each other via CLI commands. The example illustrates how a decentralized, event-driven game can be set up and managed, with commands for inviting peers, listing players, starting the game, tagging peers, and checking if you're "it." The JSON schema defines the possible game events (tag, start) and their properties, showing how structured data flows through the system. This example is ideal for developers interested in peer-to-peer applications, event-driven architectures, or implementing similar turn-based or real-time multiplayer mechanics using IPFS and Textile. The visualization emphasizes the structured output of the game setup process, making it easy to understand the underlying data model and workflow.

Aandrewxhill
55% match