Get Buy Transaction
Build an unsigned transaction for buying tokens. Endpoint:/evm/buy/transaction
| Parameter | Type | Required | Description |
|---|---|---|---|
chain | string | Yes | Chain identifier |
token | string | Yes | Token contract address |
swapMode | string | Yes | ExactIn or ExactOut |
amountIn | string | Yes | Amount of native currency in wei |
wallet | string | Yes | Wallet address |
slippageBps | number | Yes | Slippage tolerance in basis points. 0-10000 (100 = 1%) |
feeBps | number | Yes | Fee in basis points (0-175) |
feeRecipient | string | Yes | Wallet to receive fees |
sendRoute | string | No | Public, Private, or Both for MEV protection |
- Socket.IO
- HTTP
socket.emit(
"/evm/buy/transaction",
{
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
swapMode: "ExactIn",
amountIn: "1000000000000000000",
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
slippageBps: 100,
feeBps: 0,
feeRecipient: "0xYourFeeRecipientAddress",
sendRoute: "Private",
},
(response) => {
console.log(response);
}
);
await fetch("https://api.chainworks.co/evm/buy/transaction", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: CHAINWORKS_API_AUTH_TOKEN,
},
body: JSON.stringify({
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
swapMode: "ExactIn",
amountIn: "1000000000000000000",
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
slippageBps: 100,
feeBps: 0,
feeRecipient: "0xYourFeeRecipientAddress",
sendRoute: "Private",
}),
});
Get Sell Transaction
Endpoint:/evm/sell/transaction
Same parameters as buy transaction. swapMode is always ExactIn, and amountIn is the amount of tokens to sell in raw units.
Example:
- Socket.IO
- HTTP
socket.emit(
"/evm/sell/transaction",
{
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933", // PEPE
swapMode: "ExactIn",
amountIn: "1000000000000000000000000", // 1,000,000 PEPE
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
slippageBps: 100,
feeBps: 0,
feeRecipient: "0xYourFeeRecipientAddress",
},
(response) => {
console.log(response);
}
);
await fetch("https://api.chainworks.co/evm/sell/transaction", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: CHAINWORKS_API_AUTH_TOKEN,
},
body: JSON.stringify({
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933", // PEPE
swapMode: "ExactIn",
amountIn: "1000000000000000000000000", // 1,000,000 PEPE
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
slippageBps: 100,
feeBps: 0,
feeRecipient: "0xYourFeeRecipientAddress",
}),
});
Get Approve Transaction
Build a transaction to approve token spending. Endpoint:/evm/approve/transaction
| Parameter | Type | Required | Description |
|---|---|---|---|
chain | string | Yes | Chain identifier |
token | string | Yes | Token contract address |
wallet | string | Yes | Wallet granting approval |
spender | string | Yes | Contract address to approve |
allowance | string | No | Amount the spender may spend, in raw token units (default: unlimited) |
- Socket.IO
- HTTP
socket.emit(
"/evm/approve/transaction",
{
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933", // PEPE
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
spender: "0x000000000022D473030F116dDEE9F6B43aC78BA3", // Permit2
},
(response) => {
console.log(response);
}
);
await fetch("https://api.chainworks.co/evm/approve/transaction", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: CHAINWORKS_API_AUTH_TOKEN,
},
body: JSON.stringify({
chain: "eth",
token: "0x6982508145454Ce325dDbE47a25d4ec3d2311933", // PEPE
wallet: "0x10a64c6d7f12c47b7c66c5b4e20e72bc1fcd5d9e",
spender: "0x000000000022D473030F116dDEE9F6B43aC78BA3", // Permit2
}),
});

