### Installing Otomato SDK with npm Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md Use npm to install the Otomato SDK package as a project dependency. ```bash npm install otomato-sdk ``` -------------------------------- ### Create Swap and Deposit Workflow (JavaScript) Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md This example demonstrates how to build a workflow that triggers on a token price movement, swaps tokens using the Odos action, and then deposits the swapped tokens into a lending platform using the Ionic action. It initializes a price trigger, swap action, deposit action, and connects them with edges to form a complete workflow. ```JavaScript import { Workflow, Trigger, Action, Edge, TRIGGERS, ACTIONS, CHAINS, getTokenFromSymbol } from 'otomato-sdk'; // Initialize Trigger const priceTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY); priceTrigger.setChainId(CHAINS.MODE); priceTrigger.setComparisonValue(3000); priceTrigger.setCondition('lte'); priceTrigger.setParams('currency', 'USD'); priceTrigger.setContractAddress(getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress); priceTrigger.setPosition(0, 0); // Initialize Actions const swapAction = new Action(ACTIONS.SWAP.ODOS.SWAP); swapAction.setChainId(CHAINS.MODE); swapAction.setParams('amount', '1000000'); // Amount in token units swapAction.setParams('tokenIn', getTokenFromSymbol(CHAINS.MODE, 'USDT').contractAddress); swapAction.setParams('tokenOut', getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress); swapAction.setPosition(0, 100); const depositAction = new Action(ACTIONS.LENDING.IONIC.DEPOSIT); depositAction.setChainId(CHAINS.MODE); depositAction.setParams('tokenToDeposit', getTokenFromSymbol(CHAINS.MODE, 'WETH').contractAddress); depositAction.setParams('amount', swapAction.getOutputVariableName('amountOut')); depositAction.setPosition(0, 200); // Create Edges const edge1 = new Edge({ source: priceTrigger, target: swapAction }); const edge2 = new Edge({ source: swapAction, target: depositAction }); // Create Workflow const workflow = new Workflow('Swap and Deposit', [priceTrigger, swapAction, depositAction], [edge1, edge2]); ``` -------------------------------- ### Build Conditional ETH Price Monitoring Workflow (JavaScript) Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md This advanced example demonstrates creating a workflow that monitors the price of ETH and uses a split action and conditional branching to execute a specific action (sending a Slack message) only if the price meets a defined condition (e.g., below $3000). It initializes a price trigger, split action, conditional action, and Slack action, connecting them with edges including a conditional edge. ```JavaScript import { Workflow, Trigger, Action, Edge, TRIGGERS, ACTIONS, CHAINS, LOGIC_OPERATORS, ConditionGroup } from 'otomato-sdk'; // Initialize Trigger const ethPriceTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY); ethPriceTrigger.setChainId(CHAINS.MODE); ethPriceTrigger.setComparisonValue(3000); ethPriceTrigger.setCondition('lt'); ethPriceTrigger.setParams('currency', 'USD'); ethPriceTrigger.setContractAddress('ETH_CONTRACT_ADDRESS'); ethPriceTrigger.setPosition(0, 0); // Split Action const splitAction = new Action(ACTIONS.CORE.SPLIT.SPLIT); // Conditional Branches const conditionTrue = new Action(ACTIONS.CORE.CONDITION.IF); conditionTrue.setParams('logic', LOGIC_OPERATORS.OR); const conditionGroup = new ConditionGroup(LOGIC_OPERATORS.AND); conditionGroup.addConditionCheck(ethPriceTrigger.getOutputVariableName('price'), 'lt', 3000); conditionTrue.setParams('groups', [conditionGroup]); const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE); slackAction.setParams('webhook', 'YOUR_SLACK_WEBHOOK'); slackAction.setParams('message', 'ETH price is below $3000!'); // Create Edges const edge1 = new Edge({ source: ethPriceTrigger, target: splitAction }); const edge2 = new Edge({ source: splitAction, target: conditionTrue }); const edge3 = new Edge({ source: conditionTrue, target: slackAction, label: 'true', value: 'true' }); // Create Workflow const workflow = new Workflow('ETH Price Monitoring', [ethPriceTrigger, splitAction, conditionTrue, slackAction], [edge1, edge2, edge3]); ``` -------------------------------- ### Running a Workflow (JavaScript) Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md Publish the created workflow using the `create` method. If successful, execute the workflow using the `run` method and log the result or any errors. ```javascript // Publish the Workflow const creationResult = await workflow.create(); if (creationResult.success) { // Run the Workflow const runResult = await workflow.run(); if (runResult.success) { console.log('Workflow is running'); } else { console.error('Error running workflow:', runResult.error); } } else { console.error('Error creating workflow:', creationResult.error); } ``` -------------------------------- ### Creating a Workflow (JavaScript) Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md Define a workflow by initializing Trigger and Action nodes, configuring their parameters and positions, creating edges to connect them, and finally instantiating the Workflow object with a name, nodes, and edges. ```javascript import { Workflow, Trigger, Action, Edge, TRIGGERS, ACTIONS, CHAINS } from 'otomato-sdk'; // Initialize Trigger and Action nodes const priceTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY); priceTrigger.setChainId(CHAINS.MODE); priceTrigger.setComparisonValue(3000); priceTrigger.setCondition('lte'); priceTrigger.setParams('currency', 'USD'); priceTrigger.setContractAddress('TOKEN_CONTRACT_ADDRESS'); priceTrigger.setPosition(0, 0); const swapAction = new Action(ACTIONS.SWAP.ODOS.SWAP); swapAction.setChainId(CHAINS.MODE); swapAction.setParams('amount', 'AMOUNT_IN_WEI'); swapAction.setParams('tokenIn', 'TOKEN_IN_CONTRACT_ADDRESS'); swapAction.setParams('tokenOut', 'TOKEN_OUT_CONTRACT_ADDRESS'); swapAction.setPosition(0, 100); // Create Edges to connect Nodes const edge = new Edge({ source: priceTrigger, target: swapAction }); // Create Workflow const workflow = new Workflow('Swap on Price Trigger', [priceTrigger, swapAction], [edge]); ``` -------------------------------- ### Authenticating with Otomato SDK (JavaScript) Source: https://github.com/otomatorg/otomato-sdk/blob/master/README.md Authenticate your account by generating a login payload, signing it, and setting the received token for API services. Requires wallet address, chain ID, access code, owner wallet address, and signature. ```javascript import { apiServices, CHAINS } from 'otomato-sdk'; async function authenticate() { const address = 'YOUR_WALLET_ADDRESS'; const chainId = CHAINS.ETHEREUM; const accessCode = 'YOUR_ACCESS_CODE'; const loginPayload = await apiServices.generateLoginPayload(address, chainId, accessCode, ownerWalletAddress); const signature = 'SIGNATURE_OF_LOGIN_PAYLOAD'; const { token } = await apiServices.getToken(loginPayload, signature); apiServices.setAuth(token); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.