getId/setId

How to use getID and setID to create transactions

What’s the use of getId and setId?

setId and getId can be used to input data correctly across spells. Values stored in specific IDs can be stored in one spell and used in another spell.

Example of using getId and setId

Let’s say I want to sell USDC to buy ETH on 1Inch and then deposit bought ETH into Compound.

  1. So I sell USDC on 1Inch, and I store the bought ETH amount at setId (let’s say it’s 482 as setId for now) on sell() function of 1inch.

  2. Then I will use 482 as getId on compound deposit() function and deposit the bought ETH in Compound. In deposit function, I don’t need to mention the amount specifically to deposit. It will get the deposit amount from getId that is passed.

Code Snippet:

spells.add({
  connector: "oneInch",
  method: "sell",
  args: [eth_address, usdc_address, sellAmount, unitAmt, 0, "482"] // setting bought ETH amount at id 482
});

spells.add({
  connector: "compound",
  method: "deposit",
  args: [eth_address, 0, "482", 0] // getting deposit amount from id 482
});

Note:

  1. For getId, if the id is 0 then it won’t get the stored amount but it will use the amount that’s passed in the function.

  2. For setId, if the id is 0 then it won’t stored amount.

Last updated