# Join Server

{% hint style="info" %}
**Automate member joins** with a join server.

Your data union smart contract prevents addresses adding themselves as members to the data union. **Only a** [**joinPart agent**](https://docs.dataunions.org/main-concepts/roles-and-responsibilities/joinpart-agents) **can add new members** to the data union.

A join server acts as a request instance between the new member and the smart contract.

A **member sends a request** **to the server** and the **server sends** **a transaction signed by a**[ **joinPart agent**](https://docs.dataunions.org/main-concepts/roles-and-responsibilities/joinpart-agents) to the contract to add the member.
{% endhint %}

{% hint style="warning" %}
Data Union DAO provides a [**default join server**](https://github.com/dataunions/data-unions/tree/main/packages/default-join-server) that handles the automated joins via a shared secret.&#x20;

**We recommend implementing your own business logic** and set of rules under what conditions members are allowed to join. You can use **our** [**join server**](https://github.com/dataunions/data-unions/tree/main/packages/join-server) **as a starting point** (the default join server uses the join server as a base too).
{% endhint %}

{% embed url="<https://github.com/dataunions/data-unions/tree/main/packages/default-join-server>" %}
default join server
{% endembed %}

{% embed url="<https://github.com/dataunions/data-unions/tree/main/packages/join-server>" %}
base for custom join server
{% endembed %}

### Automate Member Joins With Our Default Join Server

Shared secrets **allow new members to join** the Data Union **without a manual transaction from a joinPart agent**.

The functions <mark style="color:red;">`createSecret`</mark>, <mark style="color:red;">`listSecrets`</mark> and <mark style="color:red;">`deleteSecret`</mark> can only get called by the admin. Thus the data union client private key must be from the admin.

Once you got the <mark style="color:red;">`shared secret`</mark>, save it in an **environment variable**.&#x20;

**Generate a shared secret** with the SDK:

```typescript
import { DataUnionClient } from '@dataunions/client';

const DU = new DataUnionClient({
  auth: {
    privateKey: PRIVATE_KEY_ADMIN,
  },
  // only if you don't want to use the default joinServer
  joinServerUrl: "YOUR_CUSTOM_SERVER_URL"
  chain: 'polygon',
});

const dataUnion = await DU.getDataUnion(
    DATA_UNION_CONTRACT_ADDRESS
);

// -------- ADMIN ONLY FUNCTIONS --------

// returns an object with 
// your secret string, secret_name, data union contract address and the chain
const sharedSecret = dataUnion.createSecret($custum_secret_name);

// list all your secrets
// typically there is one secret per data union
const sharedSecrets = dataUnion.listSecrets()

// -------- MEMBER FUNCTION --------

// your members can now join like this
// store the shared secret in an environment variable
const memberDetails = await dataUnion.join({
    secret:process.env.SHARED_SECRET
});
```

### Build Your Own Join Server

{% hint style="info" %}
If you build your own custom server you'll need to make an adjustment to your client setup:
{% endhint %}

```typescript
const DU = new DataUnionClient({
  auth: WALLET_PROVIDER,
  joinServerUrl: "yourURL", //add your custom joinServerUrl
  chain: 'polygon',
});
```

You might find the default join servers join requirement too basic (shared secret). We highly recommend implement your own logic. You can **use the** [**join server repository**](https://github.com/dataunions/data-unions/tree/main/packages/join-server) **as a starting point**. The default join server uses this repository as the base too.

Here you can implement logic like under **what circumstances wallet addresses can join**. E.g. only with proof of humanity verification or only addresses with an ens or only addresses that have proven to be valuable data provider. It's your decision to make.

Again **the only requirement for a member join the default join server has is providing the shared secret.** So anyone with the shared secret can essentially join the data union.

{% embed url="<https://github.com/dataunions/data-unions/tree/main/packages/join-server>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dataunions.org/main-concepts/join-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
