salt-sdk
    Preparing search index...

    Quick start

    The Salt SDK is written in TypeScript, and can be used in Node.js or the browser. Bun and Deno are untested, but may work - let us know on Discord if you give it a try!

    Run the following commands to create a new JS project with the correct dependencies.

    # Create a new project directory and create a package.json file
    mkdir salt-bot
    cd salt-bot
    npm init .

    # Install the two key dependencies
    npm install --save salt-sdk
    npm install --save-dev ethers@5.8

    You are ready to create a script that uses the Salt SDK. Most of the time, you will be using the methods on the Salt. This is the first place to look for what functionality is available in the SDK. Let's start by creating a new file called index.mjs and add the following code:

    import { Salt } from 'salt-sdk';

    async function main() {
    const salt = new Salt({
    environment: 'TESTNET',
    });

    // Step 2 code will go here
    }

    main().catch(console.error);

    You could run this by calling node index.mjs, but it won't do anything useful yet.

    Tip

    You can see more examples of how to connect to different environments in the Salt SDK constructor documentation.

    import { Salt } from 'salt-sdk';
    // New dependencies
    import { Wallet, providers } from 'ethers';

    async function main() {
    const salt = new Salt({
    environment: 'TESTNET',
    });

    // New code
    const signer = Wallet.fromMnemonic(process.env.MNEMONIC);

    await salt.authenticate(signer);
    console.log('Authenticated!');
    }

    main().catch(console.error);

    You can run this, passing the mnemonic and RPC URL as environment variables:

    MNEMONIC="your mnemonic" RPC_URL=" node index.mjs
    

    And you should see the 'Authenticated!' message.

    At this point, if the keypair you are using is already a member of an organisation and part of an account, you are ready to send a transaction. We are going to transfer some testnet $USDC on Arbitrum Sepolia (chain id: 421614).

    Warning

    Sending a transaction requires a lot of information. See the transfer and submitTx documentation for more guidance.

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

    async function main() {
    const salt = new Salt({
    environment: 'TESTNET',
    });

    // Changes: Now we are setting an RPC provider for the wallet
    const provider = new providers.JsonRpcProvider(process.env.RPC);
    const wallet = Wallet.fromMnemonic(process.env.MNEMONIC);
    const signer = wallet.connect(provider);

    await salt.authenticate(signer);

    try {
    const FROM_SALT_ACCOUNT_ID = '0EEEEEEEE';
    const TO_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
    const TOKEN = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
    const AMOUNT = '100';

    await salt.transfer({
    type: 'ERC20',
    accountId: FROM_SALT_ACCOUNT_ID,
    to: TO_ADDRESS,
    value: AMOUNT,
    tokenAddress: TOKEN,
    decimals: 6,
    chainId: 421614,
    signer: signer,
    });

    console.log(`Sent ${AMOUNT} USDC to ${TO_ADDRESS}`);
    } catch (error) {
    console.error('Transfer failed:', error);
    }
    }

    main().catch(console.error);

    Run this with the new extra parameter, RPC_URL:

    MNEMONIC="your mnemonic" RPC="https://arbitrum-sepolia.drpc.org" node index.mjs
    

    submitTx uses a similar interface, but allows you to call arbitrary smart contract functions. Check out the Salt.submitTx for an example.

    Tip

    You can list organisations this keypair is a member of using getOrganisations, and the accounts that belong to them using getAccounts.

    Tip

    You can store your Salt authentication token to avoid having to authenticate each time your code runs. See the constructor or setAuthToken. Remember to store your auth token securely if you do this.

    4. Next steps

    Using the steps outlined above, you should be in a position to start sending transactions from your Salt account. If you need more complex functionality (for example, automatically listening for account invitations), look around the SDK documentation. If something is missing, let us know in Discord.

    Now you know how to do the basics. The next steps are:

    • Learn more about the Salt SDK by exploring the API documentation.
    • Join the Salt community to connect with other developers and get help with your projects.