salt-sdk
    Preparing search index...

    Class Salt

    The Salt SDK

    Index

    Constructors

    • Creates an instance of the Salt SDK

      Parameters

      • Optionalparams: { authToken?: string; environment: Environment }

        The constructor parameters

        • OptionalauthToken?: string

          The authentication token for the Salt SDK. See Salt.authenticate for the full authentication flow, or Salt#setAuthToken to set a pre-existing token after calling the constructor.

          null
          
        • environment: Environment

          Environment to use. This will be optional in the future, but right now it is required. Use 'TESTNET'

      Returns Salt

      InvalidParams thrown if the parameters passed in to the constructor are invalid. Params are optional - the default environment is TESTNET.

      InvalidEnvironment Thrown if the provided Environment is invalid.

      InvalidAuthToken Thrown if the provided auth token is invalid. The token must be a string. If you need to authenticate, simply omit ConstructorParams.authToken, then use authenticate.

      import { Salt } from 'salt-sdk';
      import { Wallet } from 'ethers';

      const salt = new Salt({ environment: 'TESTNET' });

      // Log in to an existing account
      const signer = Wallet.createRandom();
      await Salt.authenticate(signer);

      // You are ready to use the SDK. For example...
      await salt.getBalance();
      import { Salt } from 'salt-sdk';

      const salt = new Salt({ environment: 'MAINNET' });
      import { Salt } from 'salt-sdk';

      // Connect to local development instance
      const salt = new Salt({ environment: {
      chainId: 421614,
      websocketUrl: 'https://localhost:8545',
      saltDomain: 'localhost',
      apiUrl: 'https://localhost:8545/api'
      }})
      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

    Accounts

    • Gets the details of a specific account. The user must have adequate permissions to view the account.

      Parameters

      • accountId: string

        The ID of the account

      Returns Promise<SaltAccount>

      The account details

      InvalidAuthToken if the authentication token is invalid. See authenticate for how to authenticate.

      import { Salt } from 'salt-sdk';
      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

      const account = await salt.getAccount('account-id');
      console.log(`Account: ${account.name} ID: ${account.id} Public key: ${account.publicKey}`);
    • Gets the list of token balances for an account. This list is not exhaustive.

      Parameters

      • accountId: string

        The ID of the account

      Returns Promise<TokenBalance[]>

      The list of tokens & balances

      InvalidAuthToken if the authentication token is invalid. See authenticate for how to authenticate.

      import { Salt } from 'salt-sdk';
      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

      const account = await salt.getAccountTokens('account-id');
      console.log(`ID: ${account.id} Account: ${account.name} Public key: ${account.publicKey}`);
    • Opens an API connect to receive account nudges. Nudges are ephemeral requests from another Organisation Member asking this user to join an account creation process.

      The nudge listener can be used to accept or reject nudges, and retrieve the details for the account creation process so that this API client can participate in the key material generation process.

      Parameters

      • signer: Signer

        Ethers signer, used during the account creation process

      Returns Promise<NudgeListener>

      NudgeListener for the full NudgeListener description

      const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
      const walletWithProvider = ethers.Wallet.createRandom().connect(provider);

      const salt = new Salt({
      environment: "TESTNET",
      });

      // from the nudge listener you can observe and manage your signer's reaction to nudges
      const nudgeListener = await salt.listenToAccountNudges(walletWithProvider);

      // read all the nudges in the queue
      const nudgeQueue = nudgeListener.getNudgeQueue();
      // read all the accounts for which the nudge has been processed
      const processedAccounts = nudgeListener.getAccounts();
      // stop listening to nudges
      nudgeListener.disableNudgeListener();
      // start listening again
      nudgeListener.enableNudgelistener();

    Authentication

    • Initiate the authentication flow to get an authentication token from the Salt API. This will require a signature from the Signer, which will be used to authenticate the user. If you already have an authentication token, you can set it using the setAuthToken method, or when you call the "constructor".

      A signer is required to complete the SIWER authentication flow. It is used to sign a message and a nonce, which are then validated by the Salt acceptInvitation and an auth token is returned. If you are using a browser based signer, such as Metamask, you will need to manually approve to the signature request.

      Parameters

      • signer: Signer

        The ethers signer to use for the authentication flow

      Returns Promise<string>

      long lived authentication token. This is also set on the client instance, so you do not normally need to store this manually

      InvalidUrl if the API URL or path is invalid

      Error if the authentication request fails or the user rejects signing

      import { Salt } from 'salt-sdk';
      import { ethers } from 'ethers';

      const salt = new Salt({
      environment: 'testnet',
      });

      const signer = ethers.Wallet.createRandom();
      await salt.authenticate(signer);
      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: 'testnet',
      });

      const signer = ethers.Wallet.createRandom();
      const authToken = await salt.authenticate(signer);

      // Note: this is not recommended as a secure way to store the auth token
      localStorage.setItem('salt-auth-token', authToken);
    • Sets the authentication token for the Salt SDK. This is useful if you have previously logged in and stored the token. You can also provide the token to the constructor If you do not have a token already, you can use the authenticate method to obtain one.

      Parameters

      • authToken: string

        The authentication token to use for this connection

      Returns void

      This is equivalent to providing the token to the constructor.

      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: 'testnet',
      });

      // Retrieve a previously stored auth token (note: this is not recommended as a secure way to store a token)
      const authToken = localStorage.getItem('authToken');

      salt.setAuthToken(authToken);

      // You are ready to use the SDK. For example...
      await salt.getBalance();

    Organisations

    • Accepts an Invitation to an Organisation. The list of transactions for the current user can be retrieved with getOrganisationsInvitations.

      Parameters

      • invitationId: string

        The ID of the invitation to accept

      Returns Promise<{ organisation: Organisation }>

      InvalidAuthToken if the authentication token is invalid

      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: Environment.Sandbox,
      authToken: 'your-auth-token',
      });

      const invitations = await salt.getOrganisationsInvitations();
      invitations.forEach(invitation => {
      console.log(`Accepting invitation to organisation ${invitation.organisation_id}`);
      await salt.acceptOrganisationInvitation(invitation.id);
      });
    • Gets the list of Accounts that belong to a Organisation.

      Parameters

      Returns Promise<SaltAccount[]>

      The list of accounts

      InvalidAuthToken if the authentication token is invalid. See authenticate for how to authenticate.

      import { Salt } from 'salt-sdk';
      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

      const accounts = await salt.getAccounts('organisation-id');
      accounts.forEach(account => {
      console.log(`Account: ${account.name} ID: ${account.id} Public key: ${account.publicKey}`);
      });
    • Gets the list of Organisations that the current user is a member of. Requires authentication.

      Returns Promise<Organisation[]>

      The list of organisations

      InvalidAuthToken if the authentication token is invalid. See authenticate for how to authenticate.

      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: 'testnet',
      authToken: 'your-auth-token',
      });

      const organisations = await salt.getOrganisations();
      organisations.forEach(org => {
      console.group('Organisation:', org.name);
      org.members.forEach(member => {
      console.log('Member:', member.name);
      });
      console.groupEnd();
      });
    • Returns pending Invitation to an Organisation for the current user. They can be accepted using acceptOrganisationInvitation.

      Returns Promise<{ invitations: Invitation[] }>

      List of invitations that are pending for this user

      InvalidAuthToken if the authentication token is invalid

      SocketConnectError if the socket connection could not be established

      import { Salt } from 'salt-sdk';

      const salt = new Salt({
      environment: Environment.Sandbox,
      authToken: 'your-auth-token',
      });

      const invitations = await salt.getOrganisationsInvitations();
      if (invitations.length > 0) {
      console.log('You have pending invitations');
      } else {
      console.log('No pending invitations');
      }

    Transactions

    • Gets the nonce for an account on a specific chain. The nonce is an incrementing number stored by Salt that is used to prevent replay attacks. submitTx and transfer both use the nonce, but if you do not specify one the SDK will automatically use this function to populate it.

      Parameters

      • accountId: string

        The ID of the account

      • chainId: number

        The ID of the chain

      Returns Promise<number>

      The nonce

      import { Salt } from 'salt-sdk';
      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

      const nonce = await salt.getAccountNonce('account-id', 1);
      console.log(`ID: ${account.id} Next nonce: ${nonce}`);
    • Gets the current gas price for a specific chain.

      Parameters

      • chainId: number

        The ID of the chain

      Returns Promise<GasPrice>

      The current gas price

      InvalidChain if the specified chain is unknown or unsupported

      import { Salt } from 'salt-sdk';
      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });

      const fee = await salt.getGasPrice(1);
      console.log(`Gas for Ethereum Mainnet is between ${fee.lastBaseFeePerGas} and ${fee.maxFeePerGas}`);
    • Initiate, sign and broadcast a generic transaction from a given Salt account. This method provides orchestrated transaction handling with automatic account detail fetching, multi-party signing coordination, and policy enforcement. This will require signing multiple transactions and requests:

      • Creating a transaction proposal
      • Proposing the transaction to the robos, so that the policy rules can be checked
      • Signing for broadcast to the destination network
      • Broadcasting the transaction to the destination network

      Parameters

      • params: SubmitTxParams

        The transaction parameters including account ID, recipient address, value, chain ID, transaction data, and signer. Vault details will be fetched automatically. See SubmitTxParams for the full parameter definition

      Returns Promise<Transaction>

      A Transaction object for orchestrated execution

      import { Salt } from 'salt-sdk';
      import { Wallet, utils } from 'ethers';

      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });
      const signer = Wallet.createRandom();

      // Encode the approve function call
      const iface = new utils.Interface(['function approve(address spender, uint256 amount)']);
      const data = iface.encodeFunctionData('approve', [
      '0xE592427A0AEce92De3Edee1F18E0157C05861564', // Uniswap V3 SwapRouter
      '1000000000' // 1000 USDC (6 decimals)
      ]);

      await salt.submitTx({
      accountId: '0a1b2c3d4e5f',
      to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC contract
      value: '0',
      chainId: 1,
      data: data,
      signer: signer
      });
      import { Salt } from 'salt-sdk';
      import { Wallet, utils } from 'ethers';

      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });
      const signer = Wallet.createRandom();

      // Encode the submit function call for Lido staking
      const iface = new utils.Interface(['function submit(address _referral) payable returns (uint256)']);
      const data = iface.encodeFunctionData('submit', [
      '0x0000000000000000000000000000000000000000' // No referral
      ]);

      await salt.submitTx({
      accountId: '0a1b2c3d4e5f',
      to: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84', // Lido stETH contract
      value: '1000000000000000000', // 1 ETH in wei
      chainId: 1,
      data: data,
      signer: signer
      });

      InvalidAuthToken if the auth token is missing or invalid

      InvalidSigner if the signer is missing or invalid

      WrongChain if the signer is on a different chain than expected

      SaltAccountError if the account cannot be fetched

      SocketConnectError if the websocket connection cannot be established

    • Initiate, sign and broadcast a transfer transaction from a given Salt account to a recipient address. This will require signing multiple transactions and requests:

      • Creating a transfer transaction proposal
      • Proposing the transaction to the robos, so that the policy rules can be checked
      • Signing for broadcast to the destination network
      • Broadcasting the transaction to the destination network

      Parameters

      • transfer: TransferParams

        The transfer parameters including account ID, recipient address, amount, token details, and signer. See TransferParams for the full parameter definition

      Returns Promise<Transaction>

      The result of the submitted transaction

      import { Salt, TransferType } from 'salt-sdk';
      import { Wallet } from 'ethers';

      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });
      const signer = Wallet.createRandom();

      await salt.transfer({
      type: TransferType.ERC20,
      accountId: '0a1b2c3d4e5f',
      to: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
      value: '100',
      tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
      decimals: 6,
      chainId: 1,
      signer: signer
      });
      import { Salt, TransferType } from 'salt-sdk';
      import { Wallet } from 'ethers';

      const salt = new Salt({
      environment: 'TESTNET',
      authToken: 'your-auth-token'
      });
      const signer = Wallet.createRandom();

      await salt.transfer({
      type: TransferType.Native,
      accountId: '0a1b2c3d4e5f',
      to: '0x000000000000000000000000000000000000dEaD',
      value: '1',
      decimals: 18,
      chainId: 1,
      signer: signer
      });

      InvalidAuthToken if the auth token is missing or invalid

      InvalidSigner if the signer is missing or invalid

      WrongChain if the signer is on a different chain than expected

      SaltAccountError if the account cannot be fetched

      InvalidAddress if any of the addresses (recipient, vault) are invalid

      SocketConnectError if the websocket connection cannot be established