POST
/
v0
/
multicall
/
execute
from compass_api_sdk import CompassAPI, models
from eth_account import Account
PRIVATE_KEY = "<YOUR_PRIVATE_KEY_HERE>"

with CompassAPI(
        api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
    # First get the authorization
    account = Account.from_key(PRIVATE_KEY)
    auth = compass_api.transaction_batching.authorization(
        chain=models.Chain.ETHEREUM_MAINNET,
        sender=account.address
    )

    auth_dict = auth.model_dump(mode='json', by_alias=True)

    # Sign the authorization
    signed_auth = Account.sign_authorization(auth_dict, PRIVATE_KEY)

    chain = models.Chain.ETHEREUM_MAINNET
    sender = account.address
    signed_authorization = signed_auth.model_dump(by_alias=True)

    # Then execute with the authorization
    res = compass_api.transaction_batching.execute(
        chain=chain,
        sender=sender,
        signed_authorization=signed_authorization,
        actions=[
            # Set Allowance
            models.UserOperation(
                body=models.IncreaseAllowanceParams(
                    ACTION_TYPE="ALLOWANCE_INCREASE",
                    token=models.TokenEnum.USDC,
                    contract_name=models.IncreaseAllowanceParamsContractName.UNISWAP_V3_ROUTER,
                    amount="1",
                )
            ),
            # Swap WETH for USDC on Uniswap
            models.UserOperation(
                body=models.UniswapBuyExactlyParams(
                    ACTION_TYPE="UNISWAP_BUY_EXACTLY",
                    token_in=models.TokenEnum.WETH,
                    token_out=models.TokenEnum.USDC,
                    fee=models.FeeEnum.ZERO_DOT_01,
                    max_slippage_percent=0.5,
                    amount=1,
                    wrap_eth=True,
                )
            ),
        ],
    )

    # Handle response
    print(res)
{
  "chainId": 123,
  "data": "<string>",
  "from": "<string>",
  "gas": 123,
  "to": "<string>",
  "value": 123,
  "nonce": 123,
  "maxFeePerGas": 123,
  "maxPriorityFeePerGas": 123,
  "authorizationList": []
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Body

application/json

Request model for executing a multicall.

Response

200
application/json

Successful Response

The response is of type object.