Skip to content

Instantly share code, notes, and snippets.

@vilicvane
Last active February 28, 2025 10:50
Show Gist options
  • Save vilicvane/0758a35a70bdc476e94615b3ea348571 to your computer and use it in GitHub Desktop.
Save vilicvane/0758a35a70bdc476e94615b3ea348571 to your computer and use it in GitHub Desktop.
Customize Tangem Gas Fee with Surge Script
if (
$request.method === 'POST' &&
$request.headers['Content-Type'] === 'application/json' &&
$request.headers['User-Agent'].includes('Tangem')
) {
try {
let response = JSON.parse($response.body);
let baseFeesPerGas = response.result?.baseFeePerGas;
if (baseFeesPerGas) {
let baseFeePerGas = parseInt(
baseFeesPerGas[baseFeesPerGas.length - 1].replace(/^0x/, ''),
16,
);
let [baseFee, priorityFee = baseFee * 0.2] = $argument
.split(',')
.map(segment => Number(segment));
response.result.baseFeePerGas = [
'0x' + Math.floor(Math.min(baseFee * 1e9, baseFeePerGas)).toString(16),
];
response.result.reward = [
new Array(3).fill('0x' + Math.floor(priorityFee * 1e9).toString(16)),
];
$done({
body: JSON.stringify(response),
});
} else {
$done({});
}
} catch (error) {
console.log(error);
$done({});
}
} else {
$done({});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment