Last active
February 28, 2025 10:50
-
-
Save vilicvane/0758a35a70bdc476e94615b3ea348571 to your computer and use it in GitHub Desktop.
Customize Tangem Gas Fee with Surge Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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