@keccak256-evg/passport-sdk
Version:
T-REX Passport SDK for interacting with Passport and Registry contracts
69 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createViemClient = createViemClient;
exports.createViemPublicClient = createViemPublicClient;
exports.createViemWalletClient = createViemWalletClient;
exports.getPendingBindWalletsWithViem = getPendingBindWalletsWithViem;
const viem_1 = require("viem");
const constants_1 = require("./constants");
// 向后兼容的旧函数
function createViemClient(rpcUrl) {
const viemChain = (0, viem_1.defineChain)({
id: 1962,
name: 'T-Rex Testnet',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: [rpcUrl],
},
},
blockExplorers: {
default: {
name: 'T-Rex Explorer',
url: 'https://explorer.trex.com',
},
},
testnet: true,
});
return (0, viem_1.createPublicClient)({
chain: viemChain,
transport: (0, viem_1.http)(rpcUrl),
});
}
// 新的创建函数
function createViemPublicClient(options) {
const chain = options.chain || (0, viem_1.defineChain)(constants_1.tRexTestnet);
return (0, viem_1.createPublicClient)({
chain,
transport: (0, viem_1.http)(options.rpcUrl),
});
}
function createViemWalletClient(options) {
const chain = options.chain || (0, viem_1.defineChain)(constants_1.tRexTestnet);
return (0, viem_1.createWalletClient)({
chain,
transport: (0, viem_1.http)(options.rpcUrl),
account: options.account,
});
}
// 使用 viem 调用 getPendingBindWallets 方法(需要 msg.sender 验证)
async function getPendingBindWalletsWithViem(publicClient, passportAddress, account) {
try {
const result = await publicClient.readContract({
address: passportAddress,
abi: constants_1.PASSPORT_ABI,
functionName: 'getPendingBindWallets',
account,
});
return result;
}
catch (error) {
console.error('Viem getPendingBindWallets error:', error);
throw error;
}
}
//# sourceMappingURL=utils.js.map