Creates an instance of the Salt SDK
Optionalparams: { authToken?: string; environment: Environment }The constructor parameters
OptionalauthToken?: stringThe 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.
Environment to use. This will be optional in the future, but right now it is required. Use 'TESTNET'
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' });
Gets the details of a specific account. The user must have adequate permissions to view the account.
The ID of the account
The account details
InvalidAuthToken if the authentication token is invalid. See authenticate for how to authenticate.
Gets the list of token balances for an account. This list is not exhaustive.
The ID of the account
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.
Ethers signer, used during the account creation process
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();
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.
The ethers signer to use for the authentication flow
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
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.
The authentication token to use for this connection
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();
Accepts an Invitation to an Organisation. The list of transactions for the current user can be retrieved with getOrganisationsInvitations.
The ID of the invitation to accept
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.
The ID of the Organisation
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.
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.
List of invitations that are pending for this user
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();
if (invitations.length > 0) {
console.log('You have pending invitations');
} else {
console.log('No pending invitations');
}
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.
The ID of the account
The ID of the chain
The nonce
Gets the current gas price for a specific chain.
The ID of the chain
The current gas price
InvalidChain if the specified chain is unknown or unsupported
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:
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
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
Initiate, sign and broadcast a transfer transaction from a given Salt account to a recipient address. This will require signing multiple transactions and requests:
The transfer parameters including account ID, recipient address, amount, token details, and signer. See TransferParams for the full parameter definition
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
The Salt SDK