Set up ERC-20 token approvals so Bebop’s router and settlement contracts can execute your trades.
Before settlement, the applicable contract needs permission to move your sell tokens. Call approve() on the ERC-20 token contract for the required amount.This applies to both the RFQ API (router and settlement contracts) and Aggregation API (balance manager).
Every quote response includes an approvalTarget field - this is the address you approve. Always use this value rather than hardcoding.
Never hardcode the approval address. Always read approvalTarget from the quote response.RFQ API quotes may return the router contract, settlement contract, or Permit2, depending on the flow.The Aggregation API uses a separate balance manager contract for approvals - it is not the same as the settlement contract.For Aggregation API, approving the settlement contract will lead to loss of funds.
If the current allowance is less than the trade amount, submit an approval transaction. Most integrators approve the maximum amount (2^256 - 1) so they only need to do this once per token.
from eth_account import AccountPRIVATE_KEY = "0x<your_private_key>"def ensure_allowance(account, token_address: str, spender: str, required: int): current = check_allowance(account.address, token_address, spender) if current >= required: return # already approved token = w3.eth.contract( address=Web3.to_checksum_address(token_address), abi=ERC20_ABI, ) tx = token.functions.approve( Web3.to_checksum_address(spender), 2**256 - 1, # max approval ).build_transaction({ "from": account.address, "nonce": w3.eth.get_transaction_count(account.address), "gasPrice": w3.eth.gas_price, }) signed = w3.eth.account.sign_transaction(tx, private_key=PRIVATE_KEY) tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction) w3.eth.wait_for_transaction_receipt(tx_hash, timeout=120)
Max approval (recommended for programmatic integrators): Approve 2^256 - 1 once per token. Saves gas on subsequent trades since you never need to re-approve. This is the standard approach for solvers and aggregators.Exact approval: Approve only the exact trade amount each time. More conservative, but costs gas on every trade. Some compliance-sensitive integrations prefer this.
The public RFQ and Aggregation APIs use approval_type=Standard.For BebopRouter trades, see Permit2 for self-execution.Always approve the approvalTarget from the current quote.
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Bebop API Docs","colors":{"primary":"#006623","light":"#D4FF00","dark":"#8B13CC"},"logo":{"light":"https://mintcdn.com/bebop-bfd66c5f/8ftxhO576FlbcI7H/logo_light.svg?fit=max\u0026auto=format\u0026n=8ftxhO576FlbcI7H\u0026q=85\u0026s=d48dfdf648dba1ae4d7f4cd6b02380f4","dark":"https://mintcdn.com/bebop-bfd66c5f/8ftxhO576FlbcI7H/logo_dark.svg?fit=max\u0026auto=format\u0026n=8ftxhO576FlbcI7H\u0026q=85\u0026s=74bb9c292adfad9c685b5f9f69241b69"},"favicon":{"light":"https://mintcdn.com/bebop-bfd66c5f/VcMgXhzhydk9Gm5R/favicon_light.svg?fit=max\u0026auto=format\u0026n=VcMgXhzhydk9Gm5R\u0026q=85\u0026s=6e578fac23816f11d63e7665e056bb61","dark":"https://mintcdn.com/bebop-bfd66c5f/VcMgXhzhydk9Gm5R/favicon_dark.svg?fit=max\u0026auto=format\u0026n=VcMgXhzhydk9Gm5R\u0026q=85\u0026s=b9a72733c820f67b71dfc2076a295d70"},"api":{"playground":{"display":"interactive"},"examples":{"prefill":true}},"appearance":{"default":"dark"},"footer":{"socials":{"github":"https://github.com/bebop-dex","website":"https://bebop.xyz"}},"errors":{"404":{"redirect":true}},"contextual":{"options":["copy","claude","chatgpt","cursor","vscode","add-mcp"],"display":"header"},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"bebop-bfd66c5f","hasAudioNarration":false,"actualSubdomain":"bebop-bfd66c5f","customDomains":["docs.bebop.xyz"],"gitSource":{"type":"github","owner":"bebop-dex","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ae391cbd1585fb1e11b69ad","collectionId":"8a6ab40b-2326-4e81-9b71-5e513c3c343a","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ae391cbd1585fb1e11b69ad"},"feedback":{"thumbs":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6ae868ef21b4422fadc746d6","clientVersion":"0.0.4045","searchFilterCounts":[{"language":"default","tag":"Build","count":39},{"language":"default","tag":"RFQ API","count":14},{"language":"default","tag":"Discover","count":12},{"language":"default","tag":"Guides","count":11},{"language":"default","tag":"API Reference","count":10},{"language":"default","tag":"Built for","count":8},{"language":"default","tag":"Resources","count":6},{"language":"default","tag":"Price API","count":6},{"language":"default","tag":"Aggregation API","count":5},{"language":"default","tag":"Introduction","count":5}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"custom.css","content":".home-page{max-width:768px;margin:0 auto;padding:2rem 1.5rem 4rem;color:#171717}:root.dark .home-page{color:#fff}.home-hero{text-align:center;padding:3rem 0 2.5rem}.home-hero h1{font-size:2.5rem;font-weight:700;margin:0 0 .75rem}.home-hero p{font-size:1.125rem;margin:0}.home-section{margin-top:3.5rem}.home-section h2{font-size:1.25rem;font-weight:600;margin-bottom:.75rem}.color-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:1rem;margin:1rem 0 2rem}@media (max-width:768px){.color-grid{grid-template-columns:repeat(3,1fr)}}@media (max-width:480px){.color-grid{grid-template-columns:repeat(2,1fr)}}.color-swatch{display:flex;flex-direction:column;gap:.5rem}.color-swatch-block{aspect-ratio:1;border-radius:16px;display:flex;align-items:flex-end;padding:.625rem}.color-swatch-block span{font-size:.75rem;font-weight:600;font-family:monospace}.color-swatch-label{font-size:.8125rem;font-weight:600}.logo-showcase-row{display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin:1rem 0 2rem}.logo-showcase{border-radius:16px;padding:1.25rem 1.5rem;display:grid;grid-template-columns:auto auto;grid-template-rows:1fr auto;gap:.75rem 1.5rem;align-items:center}.logo-showcase-dark{background:#171717;color:#fff}.logo-showcase-light{background:#f5f5f5;color:#171717}.logo-showcase-left{display:flex;flex-direction:column;gap:.75rem;align-items:flex-start}.logo-showcase-right{display:flex;justify-content:center;align-items:center}.logo-showcase img.logo-md,.logo-showcase img.logo-sm{height:32px;width:auto}.logo-showcase img.logo-lg{height:110px;width:auto}.logo-showcase-label{grid-column:1/-1;font-size:.75rem;opacity:.5;text-align:center}@media (max-width:640px){.logo-showcase-row{grid-template-columns:1fr}}"}],"page":{"pagePath":"core-concepts/token-approvals","slug":"/core-concepts/token-approvals","pageMetadata":{"public":true,"title":"Token Approvals","description":"Set up ERC-20 token approvals so Bebop's router and settlement contracts can execute your trades.","href":"/core-concepts/token-approvals"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Set up ERC-20 token approvals so Bebop’s router and settlement contracts can execute your trades.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Before settlement, the applicable contract needs permission to move your sell tokens. Call `,_jsx(_components.code,{children:`approve()`}),` on the ERC-20 token contract for the required amount.`]}),`\n`,_jsx(_components.p,{children:`This applies to both the RFQ API (router and settlement contracts) and Aggregation API (balance manager).`}),`\n`,_jsx(Heading,{level:`2`,id:`which-contract-to-approve`,children:`Which Contract to Approve`}),`\n`,_jsxs(_components.p,{children:[`Every quote response includes an `,_jsx(_components.code,{children:`approvalTarget`}),` field - this is the address you approve. Always use this value rather than hardcoding.`]}),`\n`,_jsxs(Warning,{children:[_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Never hardcode the approval address.`}),` Always read `,_jsx(_components.code,{children:`approvalTarget`}),` from the quote response.`]}),_jsx(_components.p,{children:`RFQ API quotes may return the router contract, settlement contract, or Permit2, depending on the flow.`}),_jsx(_components.p,{children:`The Aggregation API uses a separate balance manager contract for approvals - it is not the same as the settlement contract.`}),_jsx(_components.p,{children:`For Aggregation API, approving the settlement contract will lead to loss of funds.`})]}),`\n`,_jsx(Heading,{level:`2`,id:`check-existing-allowance`,children:`Check Existing Allowance`}),`\n`,_jsx(_components.p,{children:`Before approving, check whether the token already has sufficient allowance. This avoids unnecessary gas spend on redundant approval transactions.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`36`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`36`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` web3 `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Web3`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`ERC20_ABI`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"constant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"inputs\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"_owner\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"address\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"_spender\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"address\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"allowance\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"outputs\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"uint256\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"function\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"constant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"inputs\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"_spender\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"address\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"_value\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"uint256\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"approve\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"outputs\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"bool\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"function\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`w3 `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Web3(Web3.HTTPProvider(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://eth.llamarpc.com\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` check_allowance`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`owner`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`token_address`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`spender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` w3.eth.contract(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` address`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Web3.to_checksum_address(token_address),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` abi`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`ERC20_ABI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token.functions.allowance(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Web3.to_checksum_address(owner),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Web3.to_checksum_address(spender),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ).call()`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`approve-if-needed`,children:`Approve if Needed`}),`\n`,_jsxs(_components.p,{children:[`If the current allowance is less than the trade amount, submit an approval transaction. Most integrators approve the maximum amount (`,_jsx(_components.code,{children:`2^256 - 1`}),`) so they only need to do this once per token.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`26`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`26`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` eth_account `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Account`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`PRIVATE_KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"0x\u003cyour_private_key>\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ensure_allowance`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`account`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`token_address`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`spender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`required`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` current `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` check_allowance(account.address, token_address, spender)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` current `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` required:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # already approved`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` w3.eth.contract(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` address`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Web3.to_checksum_address(token_address),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` abi`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`ERC20_ABI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tx `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token.functions.approve(`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Web3.to_checksum_address(spender),`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 2`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`**`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`256`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` -`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# max approval`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ).build_transaction({`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"from\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: account.address,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"nonce\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: w3.eth.get_transaction_count(account.address),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"gasPrice\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: w3.eth.gas_price,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` })`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` signed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` w3.eth.account.sign_transaction(tx, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`private_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`PRIVATE_KEY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` tx_hash `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` w3.eth.send_raw_transaction(signed.raw_transaction)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` w3.eth.wait_for_transaction_receipt(tx_hash, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`120`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`using-it-with-quotes`,children:`Using It with Quotes`}),`\n`,_jsx(_components.p,{children:`After receiving a quote from either API, check and approve before signing and broadcasting:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`quote `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.json()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sell_token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` list`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(quote[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sellTokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].keys())[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sell_amount `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` int`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(quote[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sellTokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`][sell_token][`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"amount\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`approval_target `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` quote[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"approvalTarget\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`account `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Account.from_key(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`PRIVATE_KEY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`ensure_allowance(account, sell_token, approval_target, sell_amount)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Now proceed to sign and broadcast...`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`approval-strategies`,children:`Approval Strategies`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Max approval (recommended for programmatic integrators):`}),` Approve `,_jsx(_components.code,{children:`2^256 - 1`}),` once per token. Saves gas on subsequent trades since you never need to re-approve. This is the standard approach for solvers and aggregators.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Exact approval:`}),` Approve only the exact trade amount each time. More conservative, but costs gas on every trade. Some compliance-sensitive integrations prefer this.`]}),`\n`,_jsx(Heading,{level:`2`,id:`approval-type`,children:`Approval type`}),`\n`,_jsxs(_components.p,{children:[`The public RFQ and Aggregation APIs use `,_jsx(_components.code,{children:`approval_type=Standard`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`For BebopRouter trades, see `,_jsx(_components.a,{href:`/rfq-api/guides/router-migration-guide#permit2-self-execution`,children:`Permit2 for self-execution`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`Always approve the `,_jsx(_components.code,{children:`approvalTarget`}),` from the current quote.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"public":true,"title":"Token Approvals","description":"Set up ERC-20 token approvals so Bebop's router and settlement contracts can execute your trades.","href":"/core-concepts/token-approvals"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Which Contract to Approve","slug":"which-contract-to-approve","depth":2,"children":[]},{"title":"Check Existing Allowance","slug":"check-existing-allowance","depth":2,"children":[]},{"title":"Approve if Needed","slug":"approve-if-needed","depth":2,"children":[]},{"title":"Using It with Quotes","slug":"using-it-with-quotes","depth":2,"children":[]},{"title":"Approval Strategies","slug":"approval-strategies","depth":2,"children":[]},{"title":"Approval type","slug":"approval-type","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"bebop-bfd66c5f","siteName":"Bebop API Docs","title":"Token Approvals - Bebop API Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-31T14:51:47.227Z","originalFileLocation":"core-concepts/token-approvals.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Set up ERC-20 token approvals so Bebop\u0026#x27;s router and settlement contracts can execute your trades.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Bebop API Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Token Approvals - Bebop API Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Set up ERC-20 token approvals so Bebop\u0026#x27;s router and settlement contracts can execute your trades.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Bebop API Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.bebop.xyz/core-concepts/token-approvals\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://bebop-bfd66c5f.mintlify.app/_mintlify/api/og/v2?division=Core+Concepts\u0026amp;title=Token+Approvals\u0026amp;description=Set+up+ERC-20+token+approvals+so+Bebop%27s+router+and+settlement+contracts+can+execute+your+trades.\u0026amp;theme=82eb16679b59c8c5dce798b6\u0026amp;signature=ca23abdf24decc3658bd550520cce5daed07a11979b94c08712daa02eb7fe1b5\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Token Approvals - Bebop API Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Set up ERC-20 token approvals so Bebop\u0026#x27;s router and settlement contracts can execute your trades.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://bebop-bfd66c5f.mintlify.app/_mintlify/api/og/v2?division=Core+Concepts\u0026amp;title=Token+Approvals\u0026amp;description=Set+up+ERC-20+token+approvals+so+Bebop%27s+router+and+settlement+contracts+can+execute+your+trades.\u0026amp;theme=82eb16679b59c8c5dce798b6\u0026amp;signature=ca23abdf24decc3658bd550520cce5daed07a11979b94c08712daa02eb7fe1b5\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/bebop-bfd66c5f/BYvxdfgSIwp3ffIA/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Bebop API Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#006623\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.bebop.xyz/core-concepts/token-approvals\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/core-concepts/token-approvals.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.bebop.xyz/#organization\",\"name\":\"Bebop API Docs\",\"url\":\"https://docs.bebop.xyz\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/bebop-bfd66c5f/8ftxhO576FlbcI7H/logo_light.svg?fit=max\u0026auto=format\u0026n=8ftxhO576FlbcI7H\u0026q=85\u0026s=d48dfdf648dba1ae4d7f4cd6b02380f4\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.bebop.xyz#website\",\"name\":\"Bebop API Docs\",\"url\":\"https://docs.bebop.xyz\",\"publisher\":{\"@id\":\"https://docs.bebop.xyz/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.bebop.xyz/core-concepts/token-approvals#webpage\",\"url\":\"https://docs.bebop.xyz/core-concepts/token-approvals\",\"name\":\"Token Approvals\",\"description\":\"Set up ERC-20 token approvals so Bebop's router and settlement contracts can execute your trades.\",\"dateModified\":\"2026-08-31T14:51:47.227Z\",\"isPartOf\":{\"@id\":\"https://docs.bebop.xyz#website\"},\"breadcrumb\":{\"@id\":\"https://docs.bebop.xyz/core-concepts/token-approvals#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.bebop.xyz/core-concepts/token-approvals#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Core Concepts\",\"item\":\"https://docs.bebop.xyz/core-concepts/authentication\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Token Approvals\",\"item\":\"https://docs.bebop.xyz/core-concepts/token-approvals\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.bebop.xyz/core-concepts/token-approvals#article\",\"headline\":\"Token Approvals\",\"name\":\"Token Approvals\",\"description\":\"Set up ERC-20 token approvals so Bebop's router and settlement contracts can execute your trades.\",\"url\":\"https://docs.bebop.xyz/core-concepts/token-approvals\",\"mainEntityOfPage\":{\"@id\":\"https://docs.bebop.xyz/core-concepts/token-approvals#webpage\"},\"dateModified\":\"2026-08-31T14:51:47.227Z\",\"publisher\":{\"@id\":\"https://docs.bebop.xyz/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.bebop.xyz#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Bebop API Docs\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Bebop API Docs","nav":{"global":null,"tabs":[{"tab":"Home","pages":[{"title":"Home","href":"/home"}]},{"tab":"Discover","pages":[{"title":"Discover","href":"/welcome"}]},{"tab":"Build","groups":[{"group":"Introduction","pages":[{"title":"API Overview","href":"/build"}]},{"group":"Core Concepts","pages":[{"title":"Authentication","description":"How to obtain and use an API key for Bebop's trading and data APIs.","href":"/core-concepts/authentication"},{"title":"Token Approvals","href":"/core-concepts/token-approvals"},{"title":"Transaction Submission","description":"Sign and broadcast transactions from the public RFQ and Aggregation APIs.","href":"/core-concepts/execution-modes"},{"title":"Settlement \u0026 Smart Contracts","href":"/core-concepts/settlement-smart-contracts"},{"title":"Monetization","href":"/core-concepts/monetization"}]},{"group":"RFQ API","pages":[{"title":"Introduction","href":"/rfq-api/introduction"},{"title":"Quickstart","icon":"bolt","href":"/rfq-api/quickstart"},{"group":"Guides","pages":[{"title":"Partial Fills","href":"/rfq-api/guides/partial-fills"},{"title":"Multi-Token Trades","href":"/rfq-api/guides/multi-token-trades"},{"title":"Short Expiry","href":"/rfq-api/guides/short-expiry"},{"title":"Speed-Optimised Quotes","href":"/rfq-api/guides/speed-optimized-quotes"},{"title":"Indicative Quotes","href":"/rfq-api/guides/indicative-quotes"},{"title":"Best Practices","href":"/rfq-api/guides/best-practices"},{"title":"Migrating to the BebopRouter contract","href":"/rfq-api/guides/router-migration-guide"}]},{"group":"API Reference","pages":[{"title":"Indicative Quote","deprecated":null,"version":null,"openapi":"/specs/rfq-api.json post /v3/indicative-quote","href":"/rfq-api/api-reference/indicative-quote"},{"title":"Quote","deprecated":null,"version":null,"openapi":"/specs/rfq-api.json get /v3/quote","href":"/rfq-api/api-reference/quote"},{"title":"Token List","deprecated":null,"version":null,"openapi":"/specs/rfq-api.json get /v3/tokenlist","href":"/rfq-api/api-reference/token-list"},{"title":"Token Info","deprecated":null,"version":null,"openapi":"/specs/rfq-api.json get /v3/token-info","href":"/rfq-api/api-reference/token-info"},{"title":"Supported Chains","deprecated":null,"version":null,"openapi":"/specs/rfq-api.json get /chains","href":"/rfq-api/api-reference/supported-chains"}]}]},{"group":"BopAMM","pages":[{"title":"Introduction","href":"/bopamm/introduction"},{"title":"Quickstart","icon":"bolt","href":"/bopamm/quickstart"},{"group":"Guides","pages":[{"title":"Fees","href":"/bopamm/guides/fees"},{"title":"Falling back to RFQ","href":"/bopamm/guides/falling-back-to-rfq"}]}]},{"group":"Aggregation API","pages":[{"title":"Introduction","deprecated":true,"href":"/aggregation-api/introduction"},{"title":"Quickstart","icon":"bolt","href":"/aggregation-api/quickstart"},{"group":"API Reference","pages":[{"title":"Quote","deprecated":null,"version":null,"openapi":"/specs/aggregation-api.json get /v2/quote","href":"/aggregation-api/api-reference/quote"},{"title":"Competition","deprecated":null,"version":null,"openapi":"/specs/aggregation-api.json get /v2/competition/{quote_id}","href":"/aggregation-api/api-reference/competition"},{"title":"Supported Chains","deprecated":null,"version":null,"openapi":"/specs/aggregation-api.json get /chains","href":"/aggregation-api/api-reference/supported-chains"}]}]},{"group":"Price API","pages":[{"title":"Introduction","href":"/price-api/introduction"},{"title":"Quickstart","icon":"bolt","href":"/price-api/quickstart"},{"group":"Guides","pages":[{"title":"Estimating VWAP","href":"/price-api/guides/vwap-estimation"},{"title":"Pricing Unlisted Pairs","href":"/price-api/guides/pricing-unlisted-pairs"}]},{"title":"Reference","icon":"book","href":"/price-api/reference"},{"group":"Websockets","pages":[{"asyncapi":"specs/pricing-api-async.json pricing","href":"/price-api/api-reference/websockets/pricing","title":"Pricing","version":null}]}]},{"group":"Trade History API","pages":[{"title":"Introduction","href":"/trade-history-api/introduction"},{"title":"Quickstart","icon":"bolt","href":"/trade-history-api/quickstart"},{"group":"API Reference","pages":[{"title":"Trades","deprecated":null,"version":null,"openapi":"/specs/trade-history-api.json get /v2/trades","href":"/trade-history-api/api-reference/trades"},{"title":"Trade by Tx Hash","deprecated":null,"version":null,"openapi":"/specs/trade-history-api.json get /v2/tx/{tx_hash}","href":"/trade-history-api/api-reference/trade-by-tx-hash"}]}]}]},{"tab":"Resources","pages":[{"title":"Resources","href":"/support"}]},{"tab":"Market Maker Area","hidden":true,"pages":[{"title":"Market Maker Area","href":"/market-makers/overview"}]},{"tab":"Options Maker Area","hidden":true,"pages":[{"title":"Options Maker Area","href":"/market-makers/options/overview"}]}]},"basePath":"","title":"Token Approvals - Bebop API Docs","buildId":"dpl_36EDyZCDfRuoUD9af5CH4M1bqY2h","deploymentId":"dpl_36EDyZCDfRuoUD9af5CH4M1bqY2h","dynamics":[],"chunks":[]}