Anyone Docs
  • 🔷The Documentation For Anyone
    • About
    • FAQ
  • 🔷Relay Setup
    • Get Started
    • Installation and Usage
      • Setting Your Environment
        • Virtualization on Windows
        • Virtualization on macOS
        • Install Ubuntu Server 22.04
        • Server management with SSH in Windows and macOS
      • Install Anon on Linux
      • Install Anon using the apt repository
      • Update Anon and accept terms and conditions
      • Install Anon in Docker
      • Configure SOCKS5 Proxy for Anyone
      • Install Anyone Exit Relay
    • Troubleshooting Common Issues
      • Diagnosing CGNAT and Public IPv4
      • Confirm ORPort Reachability
    • Firewall and Network Configurations
      • Router Port Forwarding
      • Install and Configure Firewall
    • Advanced Configuration and Troubleshooting
      • Configure IPv4 and IPv6
      • DoS mitigation parameters
    • Relay Operator Standards
    • Exit Relay Guidelines
  • 🔷Hardware Setup
    • Setup Guide
    • Description and Specifications
    • Relay Control Panel
      • Home
      • Network Settings
      • Relay Settings
      • Relay Family
      • Proxy Settings BETA
      • Change Password
      • Logs
      • Update
    • Update (Using USB)
    • Update to WEB 3.2.0 (Using UI)
    • Troubleshooting and additional configuration
      • Router Port Forwarding
      • Diagnosing CGNAT and Public IPv4
    • Router Setup
  • 🔷Security and Privacy
    • VPS Hardening
  • 🔷Rewards Dashboard
    • Registering to the Rewards Program
    • Accessing the Rewards Dashboard
    • Using the Rewards Dashboard
    • Rewards Status
  • 🔷Anyone SDK
    • NPM SDK
      • Install NPM Package
      • Run as Library
        • Anon
        • AnonSocksClient
        • AnonControlClient
      • Run from CLI
      • Tutorials
        • Hello Anon World I
        • Hello Anon World II
        • Circuit Control I
        • Circuit Control II
    • Native SDK
      • Anyone Client Releases
      • MAN - Anon Manual
      • Tutorials
        • Anyone Services I
        • Anyone Services II
    • iOS SDK [Beta]
      • Manual Install - CocoaPods
  • 🔷Connect to Anyone
    • Connecting to Linux
      • [Beta] One-Click Linux Setup
    • Connecting to macOS
      • macOS with NPM
      • [Beta] One-Click macOS Setup
    • Connecting to Windows
      • [Beta] One-Click Windows Setup
    • Individual Applications with Anyone
    • Connect Through Hardware
  • 🔷Tokenomics
    • Introduction
    • Token Distribution
      • Token Outflow
      • Other Tokens
    • Relay Rewards
      • Lock Requirement
      • Lock Adjustments
      • Reward Multipliers
    • Additional Roles
      • Authorities and Staking
      • Governance Voting
    • Premium Circuits
      • Premium Circuits
      • Premium Circuits: Metrics
    • Summary
      • Value Accrual Summary
      • Rewards Case Study
    • Appendix
      • M Derivation
      • Risk Equation Derivation
  • 🔷Resources
    • Community and Customer Support
    • Links
    • Token
    • Whitepaper
    • Roadmap
    • API
      • REST
      • [Future] GraphQL
Powered by GitBook
On this page
  • Anon Socks Client
  • Fetching our IP

Was this helpful?

  1. Anyone SDK
  2. NPM SDK
  3. Tutorials

Hello Anon World II

PreviousHello Anon World INextCircuit Control I

Last updated 6 months ago

Was this helpful?

In part II, we will introduce the AnonSocksClient and make our first request over the internet - fetching your (new) IP address! We will continue from the node module and codebase from Hello Anon World I.

Anon Socks Client

The AnonSocksClient is used to tunnel http(s) requests through the network. It provides implementations for get, post, delete and more that automatically use a running instance of the Anyone client. It can be imported much like the Anon library:

import { AnonSocksClient } from "@anyone-protocol/anyone-client";

and instantiated immediately after the instantiation of the main anon client, taking it as reference:

// ..imports and function statements..
const anon = new Anon({ displayLog: false, socksPort: 9050, controlPort: 9051 });
const anonSocksClient = new AnonSocksClient(anon);

For those coming in from part I, you'll notice some new arguments in the anon instantiation - these are optional arguments that become relevant when dealing with SOCKS routing, circuit control and debugging. Seen in this code snippet are the default values for each one.

What are SOCKS?

These SOCKS aren't for your feet! SOCKS is an acronym for Socket Secure - an internet protocol that allows you to route your traffic to a 'proxy server' (i.e., a server that sits in between you and your eventual, varied list of destinations).

Importantly, a SOCKS proxy server can run locally, listening to any requests made on a specific port (known as 'binding' to that port). In this case, the anon SOCKS process listens to any request made to the specified socksPort, forwards this through a circuit in the Anon network, and returns the result to whichever process makes the request.

Fetching our IP

Here, we will be calling anonSocksClient.get to fetch our IP through the network. We'll be using the public, free service at , but you can choose any that works as an API! We will simply call 'get' on the API, await its result and print the result:

const response = await anonSocksClient.get('https://api.ipify.org?format=json');
console.log('Response:', response.data);

Let's see the AnonSocksClient setup and this logic in the full function (note that, for now, a short wait time is required after anon.start() and before making requests through the network).

import { Anon } from "@anyone-protocol/anyone-client";
import { AnonSocksClient } from "@anyone-protocol/anyone-client";

async function main() {
    const anon = new Anon();
    const anonSocksClient = new AnonSocksClient(anon);

    try {
        await anon.start();
        await new Promise(resolve => setTimeout(resolve, 15000));
        
        const response = await anonSocksClient.get('https://api.ipify.org?format=json');
        console.log('Response:', response.data);
        
    } catch(error) {
        console.log(error)
    } finally {
        await anon.stop()
    }
}

main()

Running node <programName>.js from the command line will show the same setup logs as before and then the result of the IP lookup! We're now, as far as external sites are concerned, coming out of Bayern, Germany. Cool!

Now, lets look into more fine-tuned circuit control.

See the full code on .

🔷
🧦
https://api.ipify.org
GitHub