IntentBuilder

The IntentBuilder is the core component of intents.js, responsible for executing the array of intents. Once you've created your intents, the next step is to pass them to the IntentBuilder for execution.

Here’s how to use 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));

Parameters for execute

The execute function takes four parameters:

  • intents: The array of intents you created.

  • signer: A signer object to sign the intent with the user's private key.

Here’s how you can create a signer using ethers.js and MetaMask:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
  • nodeUrl: A string containing your provider's URL, used to make blockchain RPC calls.

  • salt: An optional parameter representing the salt of your wallet, defaulting to 0.

Helper Function: getSender

The IntentBuilder also includes a getSender helper function, which converts your Externally Owned Account (EOA) wallet to your Smart Wallet (SW) address.

Here’s how to use it:

intentBuilder.getSender(signer, ?salt)

Last updated