29 lines
687 B
JavaScript
29 lines
687 B
JavaScript
|
|
import { keccak256, toHex } from 'viem'
|
||
|
|
|
||
|
|
// 计算函数选择器
|
||
|
|
function getFunctionSelector(signature) {
|
||
|
|
const hash = keccak256(toHex(signature))
|
||
|
|
return hash.slice(0, 10) // 前4字节
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('\n计算函数选择器...\n')
|
||
|
|
|
||
|
|
const signatures = [
|
||
|
|
'deposit(address,uint256)',
|
||
|
|
'supplyCollateral(address,uint256)',
|
||
|
|
'supply(address,uint256)',
|
||
|
|
'supplyTo(address,address,uint256)'
|
||
|
|
]
|
||
|
|
|
||
|
|
signatures.forEach(sig => {
|
||
|
|
const selector = getFunctionSelector(sig)
|
||
|
|
console.log(`${sig}`)
|
||
|
|
console.log(` 选择器: ${selector}`)
|
||
|
|
if (selector === '0x47e7ef24') {
|
||
|
|
console.log(' ✓ 匹配!')
|
||
|
|
}
|
||
|
|
console.log()
|
||
|
|
})
|
||
|
|
|
||
|
|
console.log('错误消息中的选择器: 0x47e7ef24')
|