# Getting Started

## NPM Package

{% embed url="<https://www.npmjs.com/package/@startbahn/startrail-sdk-js>" %}

| Env        | Tag                                                                |
| ---------- | ------------------------------------------------------------------ |
| Staging    | <https://www.npmjs.com/package/@startbahn/startrail-sdk-js/v/next> |
| Production | <https://www.npmjs.com/package/@startbahn/startrail-sdk-js>        |
|            |                                                                    |

## Add Packages <a href="#implementation" id="implementation"></a>

{% tabs %}
{% tab title="npm" %}

```
npm install @startbahn/startrail-sdk-js
```

{% endtab %}

{% tab title="yarn" %}

```
yarn add @startbahn/startrail-sdk-js
```

{% endtab %}
{% endtabs %}

## Script Tag <a href="#implementation" id="implementation"></a>

{% hint style="info" %}
Please ensure to check and update to the latest version when you are developing.
{% endhint %}

{% tabs %}
{% tab title="jsdeliver" %}

```
<script src="https://cdn.jsdelivr.net/npm/@startbahn/startrail-sdk-js@1.34.0/dist/startrail-sdk.min.js"></script>
```

{% endtab %}

{% tab title="unpkg" %}

```
<script src="https://unpkg.com/@startbahn/startrail-sdk-js@1.34.0"></script>
```

{% endtab %}
{% endtabs %}

## Import <a href="#implementation" id="implementation"></a>

```
const StartrailSdk = require('@startbahn/startrail-sdk-js').Startrail
// or
import StartrailSdk from "@startbahn/startrail-sdk-js";

const startrail = new StartrailSdk(config)
```

## Constructor

Configure and construct your Startrail SDK instance

```
new StartrailSdk(config)
```

### Properties

All the properties listed below are *optional*.

<table><thead><tr><th width="213">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>apiPath</td><td><code>string</code></td><td><p>Only define it if you want to do testing. For testing use the <code>Test</code> environment URL of STARTRAIL:</p><p><code>https://api-stg.startrail.startbahn.jp/api/v1</code></p><p>For production purpose do not define it.</p></td></tr><tr><td>wallet</td><td><code>'startrail' | 'metamask'</code></td><td><p>Wallet to activate. Default is <code>startrail.</code></p><ul><li><code>metamask</code>: Metamask wallet installed in users' environment.</li><li><code>startrail</code>: Google or Email/Password powered by Web3Auth.</li></ul></td></tr><tr><td>env</td><td><code>string</code></td><td><p>The environment of Startrail-Api endpoint, blockchain network and Web3Auth environment.<br></p><ul><li><code>production</code>: Matic network. TORUS production account and Startrail production Auth0 account. It is designed to communicate to Startrail production API.</li><li><code>staging</code>: Mumbai network. TORUS production account and Startrail staging Auth0 account. It is designed to communicate to Startrail for testing.</li></ul><p><br></p></td></tr><tr><td>authAction</td><td><pre class="language-typescript"><code class="lang-typescript">{
  login: boolean
  signup: boolean
}
</code></pre></td><td>true hashes the preimage with keccak256</td></tr><tr><td>auth0ClientId</td><td><code>string</code></td><td>Client ID of Auth0 account</td></tr><tr><td>auth0Domain</td><td><code>string</code></td><td>Domain URL of Auth0</td></tr><tr><td>auth0TorusConfigKey</td><td><code>string</code></td><td>Config key name for TORUS initialisations to connect Auth0 domain and Web3Auth network. This key is only provided by Web3Auth</td></tr><tr><td>lang</td><td><pre class="language-typescript"><code class="lang-typescript"> 'ja' | 'en'
</code></pre></td><td>Language displayed on the UI</td></tr><tr><td>loginProvider</td><td><pre class="language-typescript"><code class="lang-typescript">['google' | 'email_passwordless' | 'facebook' | 'twitter' | 'line' | 'apple' | 'email_password']
</code></pre></td><td>login providers for connecting wallet, more detail <a href="/pages/WeiVC5tPvXJn8KxpzB0O">here</a>.</td></tr><tr><td>customUi</td><td><a href="/pages/ArKSzO1J1eosVczBoEWW"><code>CustomUI</code></a></td><td>Values to customise UI only under Startrail wallet powered by Web3Auth.<br><br>See more details in <a data-mention href="/pages/ArKSzO1J1eosVczBoEWW">/pages/ArKSzO1J1eosVczBoEWW</a> section.</td></tr><tr><td>callbackUrl</td><td><code>string</code></td><td>A URL to which a user is redirected after completing email verification with <code>email_password</code></td></tr><tr><td>withModal</td><td><code>boolean</code></td><td>Startrail modal powered by Web3Auth is opened instead of direct procedure with a specific login action.</td></tr><tr><td>rpcEndpoint</td><td><code>string</code></td><td>An <code>rpcEndpoint</code> that is accessed from the wallet you select. See for more detail <a href="/pages/MbQfOZXGMkqDaEe1RIN8">here</a>.</td></tr><tr><td>chainId</td><td><code>number</code></td><td>An <code>chainId</code> that is accessed from the wallet you select. See for more detail <a href="/pages/MbQfOZXGMkqDaEe1RIN8">here</a>.</td></tr><tr><td>mfaLevel</td><td><code>"none" | "default" | "optional" | "mandatory"</code></td><td>default is <code>none</code> that is not asking for MFA. Further detail is <a href="https://web3auth.io/docs/sdk/pnp/unreal/mfa#mfalevel">here</a>.</td></tr></tbody></table>

{% hint style="warning" %}
We recommend encouraging users to use this SDK in standard web browsers, such as Safari, Chrome, Firefox, etc. Some functionality of the SDK may not work properly in [web-views](https://en.wikipedia.org/wiki/WebView).
{% endhint %}

### Sample Config Values For Each Login Method

{% tabs %}
{% tab title="All" %}

```
// For Production (*No need to set auth0 or apiPath)
sdk = new Startrail({
  lang: 'ja',
  withModal: true,
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  withModal: true,
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Google" %}

```
// For Production (*No need to set auth0 or apiPath)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['google'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['google'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Email Passwordless" %}

```
// For Production (*apiPath setting is not required)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['email_passwordless'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['email_passwordless'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Line" %}

```
// For Production (*apiPath setting is not required)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['line'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['line'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Facebook" %}

```
// For Production (*apiPath setting is not required)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['facebook'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['facebook'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Apple" %}

```
// For Production (*apiPath setting is not required)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['apple'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['apple'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="Twitter" %}

```
// For Production (*apiPath setting is not required)
sdk = new Startrail({
  lang: 'ja',
  loginProvider: ['twitter'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  lang: 'ja',
  loginProvider: ['twitter'],
  env: 'staging', // torusBuildEnv is deprecate after v1.25.0
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}

{% tab title="MetaMask" %}

```
// For Production (*No need to set auth0 or apiPath)
sdk = new Startrail({
  env: 'production',
  wallet: 'metamask'
})

// For Development
sdk = new Startrail({
  apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
  env: 'staging',
  wallet: 'metamask'
})
```

{% endtab %}

{% tab title="Email Password" %}

```
// For Production (*No need to set auth0 or apiPath)
sdk = new Startrail({
  authAction: { login: false, signup: true },
  lang: 'ja',
  loginProvider: ['email_password'],
  env: 'production',　// torusBuildEnv is deprecate after v1.25.0
  redirectUrl: 'https://yoursite.com', // Not necessary for login
  customUi: {
    logoUrl: 'https://yoursite.com/logo',
    serviceName: 'your service name'
  }
})

// For Development
sdk = new Startrail({
　authAction: { login: false, signup: true },
　apiPath: 'https://api-stg.startrail.startbahn.jp/api/v1',
　lang: 'ja',
　loginProvider: ['email_password'],
　env: 'staging', // torusBuildEnv is deprecate after v1.25.0
　redirectUrl: 'https://yoursite.com', // Not necessary for login
　customUi: {
　　logoUrl: 'https://yoursite.com/logo',
　　serviceName: 'your service name'
　},
  // rpcEndpoint: 'your rpc endpoint url' // IF you want to designate endpoint
})
```

{% endtab %}
{% endtabs %}

To connect to your wallet, use `login` method

```
await sdk.login()
```

See more details in [Wallet Methods](/startrail-sdk-js/wallet-methods.md)

{% hint style="info" %}
Auth0, managed by Startbahn, is used for certain authentication methods, such as Email Password.
{% endhint %}


---

# 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.startrail.io/startrail-sdk-js/getting-started.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.
