IntentBuilder

The IntentBuilder is the core component of intents.js. He is in charge of executing the array of Intents.

After declaring the Intents array, the next step will be to deliver it to the IntentBuilder to execute.

This is an example of usage of the IntentBuilder:

const intentBuilder = new IntentBuilder();

intentBuilder.execute(intents, signer, nodeUrl, salt)
    .then(() => console.log('Intent executed successfully.'))
    .catch((error) => console.error('Error executing intent:', error));

The execute function is expecting four parameters:

intents - an array from type intent. What we created in the Intent Class part.

signer - a signer object, use for signing the intent with the user own private key.

This is a simple example how to create the signer object using ethers.js and the MetaMask sdk:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

nodeUrl - string of your provider url, to make blockchain rpc calls.

salt - an optional parameter. The salt of your wallet. Default value is 0.

getSender

The IntentBuilder have another helper function, for translate your EOA wallet - to your SW address.

This is a simple example of usage:

intentBuilder.getSender(signer, ?salt)

Last updated