Authereum
Search…
SDK

Authereum SDK

Using Authereum as a Web3 provider is recommended, but you can also use the Authereum SDK directly.
Example of initializing Authereum SDK:
1
import Authereum from 'authereum
2
3
const authereum = new Authereum('kovan')
Copied!

Options:

  • Networks
    • mainnet
    • kovan
    • rinkeby
    • ropsten
    • goerli
  • Configuration object and overrides
    • config
      • networkName - default: mainnet
      • apiKey - default: null use your API key
      • 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
  • Example:
    1
    const authereum = new Authereum({
    2
    networkName: 'kovan',
    3
    disableNotifications: true
    4
    })
    Copied!
    • Example:
      1
      const authereum = new Authereum({
      2
      rpcUri: 'https://kovan.infura.io'
      3
      })
      Copied!
NOTE: Using private chains or custom local RPC urls are not supported at the moment. Read the FAQ for more info.

Events

  • ready
    • 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()
    • 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.
  • 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 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:
        • 1
          authereum.addFunds({
          2
          countryCode: 'US',
          3
          tokenSymbol: 'DAI',
          4
          sourceAmount: 25
          5
          })
          Copied!
  • version()
    • Returns the SDK version.

Browserify example

Install authereum sdk:
1
npm i authereum
Copied!
Install browserify globally:
1
npm i -g browserify
Copied!
Initialize authereum sdk in index.js
1
const { Authereum } = require('authereum')
2
3
const authereum = new Authereum()
4
authereum.login()
Copied!
Browserify index.js to create a bundled file which can be ran in the browser:
1
browserify index.js > bundle.js
Copied!
Include the script tag with bundle.js in your html:
1
<!DOCTYPE html>
2
<html lang="en-US">
3
<head>
4
<meta charset="UTF-8">
5
<title></title>
6
</head>
7
<body>
8
<script src="bundle.js"></script>
9
</body>
10
</html>
11
Copied!

Examples

Logging in:

1
import Authereum from 'authereum
2
3
const authereum = new Authereum('kovan')
4
await authereum.login()
Copied!

Getting account address:

1
import Authereum from 'authereum
2
3
const authereum = new Authereum('kovan')
4
const address = await authereum.getAccountAddress()
Copied!

Events:

1
import Authereum from 'authereum
2
3
const authereum = new Authereum('kovan')
4
5
authereum
6
.on('ready', () => {
7
console.log('ready')
8
})
9
.on('error', err => {
10
console.error(err)
11
})
Copied!
Last modified 1yr ago