# SDK

## Authereum SDK

Using Authereum as a[ Web3 provider](/web3-provider.md) is recommended, but you can also use the Authereum SDK directly.

Example of initializing Authereum SDK:

```javascript
import Authereum from 'authereum

const authereum = new Authereum('kovan')
```

### Options:

* Networks
  * `mainnet`
  * `kovan`
  * `rinkeby`
  * `ropsten`
  * `goerli`<br>
* Configuration object and overrides
  * config
    * `networkName` - default: `mainnet`
    * `apiKey` - default: `null` use your [API key](/api-keys.md)
    * `rpcUri` - default: `https://mainnet.rpc.authereum.com`
    * `webUri` - default: `https://authereum.com`
    * `xsUri` - default: `https://x.authereum.com`
    * `disableNotifications` - default: `false`
    * `blockedPopupRedirect` - default `true`
    * `forceRedirect` - default `false`
* &#x20;Example:

  ```javascript
  const authereum = new Authereum({
    networkName: 'kovan',
    disableNotifications: true
  })
  ```
* * Example:

    ```javascript
    const authereum = new Authereum({
      rpcUri: 'https://kovan.infura.io'
    })
    ```

NOTE: Using private chains or custom local RPC urls are not supported at the moment. Read the [FAQ](https://developers.authereum.org/faq) for more info.

### Events

* `ready`&#x20;
  * &#x20;Emitted when SDK is ready to be used
* `iframeReady`
  * Emitted when iframe connection is ready
* `openPopup`

  Emitted when popup has opened, typically from a login request.
* `closePopup`
  * Emitted when popup has closed, typically from logging in.
* `popupBlocked`
  * Emitted when the login popup is blocked by the browser.
* `login`
  * Emitted when user successfully logged in.
* `logout`
  * Emitted when user logs out.
* `dappKeyExpired`
  * Emitted when the dapp key expires.
* `error`
  * Emitted when ever there's an error.

### Methods

* `login()`
  * Show login window to authenticate.
* `logout()`
  * Logout from dapp.
* `showWidget(bool?)`
  * Show Authereum widget on page.
* `hideWidget()`&#x20;
  * Hide Authereum widget from page.
* `getDappKey()`
  * Get  logged in user's dapp key info like public address
* `getTransactionReceipt(transactionHash)`
  * Returns the transaction receipt with `receipt.status` being `false` if the top-level transaction failed or any of the internal transactions failed. The receipt status will be `true` if both the top-level transaction succeeded and all the internal transactions succeeded.&#x20;
* `hasRecoveryEnabled()`
  * Returns `true` if user has a recovery option set.
* `waitForTransactionReceipt(transactionHash)`
  * Will wait for transaction to be mined to return transaction receipt.
* `signMessageWithSigningKey(message)`
  * Sign a message using a persistent key dedicated for signing message. Check [browser compatibility](/browser-compatibility.md) before using this method since it relies on cross-site storage.
* `getSigningKeyAddress()`
  * Returns the public address of the signing key.
* `isAuthenticated()`
  * Returns `true` if user is logged into dapp with Authereum.
* `isContractDeployed(accountAddress?)`
  * Returns `true` if account address is a deployed contract.
* `addFunds(options?)`
  * Render a fiat on-ramp modal to buy ETH or DAI.
  * The optional options object is for filtering the payment options available.
    * `countryCode` : 2-letter country code (ie 'US', 'GB', etc)
    * `tokenSymbol` : Token symbol (ie 'ETH', 'DAI' ,etc)
    * `sourceAmount` : Source fiat amount (ie 25, 100, etc)
    * Example:
      * ```
        authereum.addFunds({
          countryCode: 'US',
          tokenSymbol: 'DAI',
          sourceAmount: 25
        })
        ```
* `version()`
  * Returns the SDK version.

## Browserify example

Install authereum sdk:

```bash
npm i authereum
```

Install browserify globally:

```bash
npm i -g browserify
```

Initialize authereum sdk in `index.js`&#x20;

```javascript
const { Authereum } = require('authereum')

const authereum = new Authereum()
authereum.login()
```

Browserify `index.js` to create a bundled file which can be ran in the browser:

```bash
browserify index.js > bundle.js
```

Include the script tag with `bundle.js` in your html:

```markup
<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <script src="bundle.js"></script>
</body>
</html>

```

## Examples

### **Logging in:**

```javascript
import Authereum from 'authereum

const authereum = new Authereum('kovan')
await authereum.login()
```

### **Getting account address:**

```javascript
import Authereum from 'authereum

const authereum = new Authereum('kovan')
const address = await authereum.getAccountAddress()
```

### **Events:**

```javascript
import Authereum from 'authereum

const authereum = new Authereum('kovan')

authereum
.on('ready', () => {
  console.log('ready')
})
.on('error', err => {
  console.error(err)
})
```


---

# 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.authereum.com/sdk.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.
