To access the 1inch API, send a GET request to any of the URLs outlined in the docs depending on what function you need.
For the example below, the swap endpoint is being called. Before any swap request is called, make sure 1inch v3 has approval to spend the token being traded. Approvals can be done with the request found here https://docs.1inch.io/api/approve
The "tx" JSON object can be signed with a private key, ethersjs will automatically populate fields deleted except for data.
Ethersjs will automatically sign, serialize, and send all in one step.
Finally, the transaction can be converted over to a hexadecimal string and the web3 provider is used to broadcast the transaction.
To use this example on another chain, change the “137” in the swap url to 56 (BSC) or 1 (ETH). The provider should also be changed to one that supports the chain specified, like infura for Ethereum or Ankr for BSC.