All requests and examples are made for Ethereum mainnet, if you plan to use the API for Binance Smart Chain, change the request url as follows: https://api.1inch.exchange/v3.0/56/<method>
0
— set approval to zero (lock a token)
>0
— approve exact amount of tokens.{"to": ["string" // token contract address],"value": "string", // amount of eth to be sent (in wei)"gasPrice": "string", // recommended gas price (in wei)"data": "string" // result calldata}
Do not combine amount
parameter with infinity
parameter, only one must be sent.
amount
is set in minimal divisible units: for example, to unlock 1 DAI, amount
should be 1000000000000000000
, to unlock 1.03 USDC, amount
should be 1030000
.
Request url to unlock 5000 DAI tokens
https://api.1inch.exchange/v3.0/1/approve/calldata?amount=5000000000000000000000&tokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f
curl
curl -X GET "https://api.1inch.exchange/v3.0/1/approve/calldata?amount=5000000000000000000000&tokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f" -H "accept: application/json"
{"data": "0x095ea7b3000000000000000000000000111111125434b319222cdbf8c261674adb56f3aeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff","gasPrice": "51000000000","to": "0x6b175474e89094c44da98b954eedeac495271d0f","value": "0"}
access-control-allow-origin: *cache-control: public,max-age=300,s-maxage=300cf-cache-status: EXPIREDcf-ray: 5f4206653b48e69c-LHRcf-request-id: 067d2253420000e69c3e176000000001content-encoding: gzipcontent-type: application/json; charset=utf-8date: Wed,18 Nov 2020 13:26:45 GMTetag: W/"ec-iBWHynvCWl7Z7aoQEOVh6S9MqaM"expect-ct: max-age=604800,report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"server: cloudflarestatus: 200vary: Origin,Accept-Encodingx-powered-by: Express
Please, note some token contracts, like USDT, require to set approval back to zero, before increasing it.
It is recommended to make an estimate of this transaction before sending it to the node.
Test your request in web interface: https://api.1inch.exchange/swagger/ethereum/#/Approve/ApproveController_getCallData
{"address": "string" // address of 1inch contract}
Request url
https://api.1inch.exchange/v3.0/1/approve/spender
curl
curl -X GET "https://api.1inch.exchange/v3.0/1/approve/spender" -H "accept: application/json"
{"address": "0x111111125434b319222cdbf8c261674adb56f3ae"}
access-control-allow-origin: *cache-control: public,max-age=300,s-maxage=300cf-cache-status: REVALIDATEDcf-ray: 5f4d1eb46d9807aa-LHRcf-request-id: 06841184c0000007aa76229000000001content-encoding: gzipcontent-type: application/json; charset=utf-8date: Thu,19 Nov 2020 21:45:44 GMTetag: W/"38-OVahTHEixCdKnQb1Zt3v5Gr5QvY"expect-ct: max-age=604800,report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"server: cloudflarestatus: 304vary: Origin,Accept-Encodingx-powered-by: Express
Test your request in web interface: https://api.1inch.exchange/swagger/ethereum/#/Approve/ApproveController_getSpender