See intents.js documentation at docs.balloondogs.network
To include intents.js
in your project, ensure you have Node.js and npm installed in your environment and run the following command:
npm install intents.js
Import intents.js
into your project to begin defining intents:
import { IntentBuilder, InterfaceIntent, Projects } from 'intents.js';
Create an instance of the IntentSDK
:
const intentBuilder = new IntentBuilder();
After initializing the SDK, you need to configure it with your signing key and node URL. Replace the placeholders with your actual signing key and node URL:
const nodeUrl = "<Your_Node_URL_Here>";
To build an array of intents for our bundler to solve, you can directly utilize the predefined interfaces. Here's an example demonstrating how to construct the intents
array with specific transaction intentions:
const intents: InterfaceIntent =
{
from: {
type: "TOKEN",
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
amount: 2300,
chainId: BigNumber.from("1")
},
to: {
type: "TOKEN",
address: "NATIVE", // ETH as native currency
amount: 1,
chainId: BigNumber.from("1")
},
extraData: {
expirationDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), // 24 hours from now
partiallyFillable: false,
kind: "sell"
}
}
After setting up your intents array, the next step is to execute these intents using the IntentBuilder
. This process involves calling the execute
method on your intentBuilder
instance, passing in the necessary parameters such as the intents array, your signing key, and the node URL. The execution is handled asynchronously.
intentBuilder.execute(intents, signer, nodeUrl)
.then(() => console.log('Intent executed successfully.'))
.catch((error) => console.error('Error executing intent:', error));
The intents.js
SDK simplifies interactions with staking operations through the Projects
class. This utility class provides quick access to the addresses of well-known staking providers, making it easier to reference them when building staking-related intents.
BeaconChain
Lido
RocketPool
Mantle
StakeWise
Ankr
Swell
Liquid
Binance
Stader
Origin
Frax
Coinbase
Aave
Compound
Spark
SushiSwap
When defining an intent to stake with a specific provider, you can reference the provider's address directly through the Projects
class. Here's how you can specify staking with Lido as an example:
to: {
type: "STAKE",
address: Projects.Staking.Lido
},