# joinCampaign(\[campaignParams,])

<pre class="language-typescript"><code class="lang-typescript">const campaignId = '02jd020jkd-302jdi2d-02ij0dj';

await userClient.joinCampaign(
   {
      campaign: {
         id: campaignId
      },
      referrer: 'ABC1245' //optional
   }
<strong>)
</strong></code></pre>

## Params

<table><thead><tr><th width="180">Param</th><th width="110">Required</th><th width="80">Type</th><th>Description</th></tr></thead><tbody><tr><td>campaign.id</td><td>required</td><td>String</td><td>the  <a href="broken-reference">id of the program/campaign</a> the user should be added to.<br>Note: this campaign/program must belong to your account.</td></tr><tr><td>referrer</td><td>optional</td><td>String</td><td>the referrer's referral code - if passed in, a referral linking will be attempted. No referral will be made if the user was already referred.</td></tr></tbody></table>

## **Response**

```typescript
void
```

### Examples

**Joining a referred user in a gated referral program so a user can become a referrer** &#x20;

In both browser and Server-side examples, we're able to provide an optional referrerId to link the referrer to the joining user if they were referred.

{% tabs %}
{% tab title="Browser" %}
In this example we use the getReferrerId utility to fetch a referrerId from the browser session. If a referrer Id was saved before .joinCampaign is called, it&#x20;

```typescript
import { ChainvineClient, getReferrer } from '@chainvine/sdk';

const referrer = getReferrer();
const userWalletAddress = '0x293kdo0ij0';
const campaignId = 'aSlug23';
const wallet = 'Hiodn2oD2dkmo2';

const client = new ChainvineClient(); //Make sure to whitelist your domain
const userClient = await client.syncUser(userWalletAddress);

await userClient.joinCampaign(
   {
      campaign: {
         id: campaignId
      },
      referrer, //Optional
   }
)
```

{% endtab %}

{% tab title="Server Side" %}

```typescript
import { ChainvineClient } from '@chainvine/sdk';

const referrer = 'aReferralCode';
const userWalletAddress = '0x293kdo0ij0';
const campaignId = 'aSlug23';
const wallet = 'Hiodn2oD2dkmo2';

// Generate your ChainvineClient instance
const client = new ChainvineClient({
    apiKey: '0dj03j000d'  // Your API Key
});
const userClient = await client.syncUser(userWalletAddress);

await userClient.joinCampaign(
   {
      campaign: {
         id: campaignId
      },
      referrer, //Optional
   }
)
```

{% endtab %}
{% endtabs %}


---

# 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.chainvine.xyz/developers/sdk/classes-and-functions/chainvineuser/joincampaign-campaignparams.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.
