42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
|
|
import { createPublicClient, http } from 'viem';
|
|||
|
|
import { arbitrumSepolia } from 'viem/chains';
|
|||
|
|
|
|||
|
|
const CONFIGURATOR_ADDRESS = '0x488409CE9A3Fcd8EbD373dCb7e025cF8AB96fcdc';
|
|||
|
|
|
|||
|
|
// ERC-1967 标准存储槽
|
|||
|
|
const IMPLEMENTATION_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc';
|
|||
|
|
|
|||
|
|
const publicClient = createPublicClient({
|
|||
|
|
chain: arbitrumSepolia,
|
|||
|
|
transport: http('https://sepolia-rollup.arbitrum.io/rpc')
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
async function getImplementation() {
|
|||
|
|
console.log('🔍 查找代理合约的实现地址\n');
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 读取 ERC-1967 实现槽
|
|||
|
|
const slot = await publicClient.getStorageAt({
|
|||
|
|
address: CONFIGURATOR_ADDRESS,
|
|||
|
|
slot: IMPLEMENTATION_SLOT
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (slot && slot !== '0x' + '0'.repeat(64)) {
|
|||
|
|
// 从存储槽中提取地址(去掉前面的0)
|
|||
|
|
const implementationAddress = '0x' + slot.slice(-40);
|
|||
|
|
console.log('✅ 找到实现合约:');
|
|||
|
|
console.log(` 代理合约 (Configurator): ${CONFIGURATOR_ADDRESS}`);
|
|||
|
|
console.log(` 实现合约 (Implementation): ${implementationAddress}`);
|
|||
|
|
console.log(`\n📊 查看实现合约源码:`);
|
|||
|
|
console.log(` https://sepolia.arbiscan.io/address/${implementationAddress}#code`);
|
|||
|
|
console.log(`\n💡 提示: 需要使用实现合约的 ABI,但调用代理合约的地址`);
|
|||
|
|
} else {
|
|||
|
|
console.log('❌ 未找到实现地址');
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 错误:', error.message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
getImplementation();
|