SqueekChain Sepolia Nft Claim Console Script
(async function universalClaimNft() {
try {
if (!window.ethereum) {
alert("No Ethereum wallet found. Please install MetaMask, Rabby, or a Web3 wallet.");
return;
}
// 1. Connect wallet and enforce Sepolia chain (11155111 / 0xaa36a7)
console.log("⏳ Connecting wallet...");
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
const userAddress = accounts[0];
console.log("Connected account:", userAddress);
const sepoliaChainIdHex = '0xaa36a7';
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: sepoliaChainIdHex }],
});
} catch (switchError) {
if (switchError.code === 4902) {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: sepoliaChainIdHex,
chainName: 'Sepolia Testnet',
nativeCurrency: { name: 'Sepolia ETH', symbol: 'SEP', decimals: 18 },
rpcUrls: ['https://rpc.sepolia.org'],
blockExplorerUrls: ['https://eth-sepolia.blockscout.com']
}]
});
}
}
// 2. Dynamically extract the active user's authorization from React Query cache
function extractAuthFromMemory() {
try {
const elements = document.querySelectorAll('*');
for (const el of elements) {
for (const key in el) {
if (key.startsWith('__reactFiber') || key.startsWith('__reactInternalInstance')) {
let fiber = el[key];
while (fiber) {
const client = fiber.memoizedProps?.client || fiber.stateNode?.props?.client;
if (client && typeof client.getQueryCache === 'function') {
const queries = client.getQueryCache().getAll();
for (const q of queries) {
const data = q.state?.data;
// Match authorization object regardless of wrapping
if (data?.authorization?.signature) return data.authorization;
if (data?.signature && data?.authorizationId) return data;
}
}
fiber = fiber.return;
}
}
}
}
} catch (e) {
console.warn("React cache extraction encountered an error:", e);
}
return null;
}
let auth = extractAuthFromMemory();
// 3. Fallback: If memory hasn't populated yet, ask the user to paste their auth JSON
if (!auth) {
const input = prompt(
"Could not auto-detect authorization from page cache.\n\n" +
"Please paste your authorization JSON (from the DevTools Network tab -> 'mint/status' or 'mint/authorization'):"
);
if (!input) {
console.log("Operation cancelled.");
return;
}
try {
const parsed = JSON.parse(input);
auth = parsed.authorization || parsed;
} catch (err) {
alert("Invalid JSON format provided.");
return;
}
}
// Validate required fields
if (!auth.signature || !auth.authorizationId || !auth.deadline || !auth.quantity) {
alert("Missing required fields in authorization (signature, authorizationId, deadline, quantity).");
return;
}
console.log("✅ Using Authorization Data:", auth);
// 4. ABI Encoding for claim(address,uint256,bytes32,uint256,bytes) - Selector 0x3374b3df
const methodId = "3374b3df";
const recipient = (auth.recipient || userAddress).toLowerCase().replace("0x", "").padStart(64, "0");
const quantity = BigInt(auth.quantity).toString(16).padStart(64, "0");
const authorizationId = auth.authorizationId.toLowerCase().replace("0x", "").padStart(64, "0");
const deadline = BigInt(auth.deadline).toString(16).padStart(64, "0");
// Offset for dynamic bytes: 5 arguments * 32 bytes = 160 (0xa0)
const offset = (160).toString(16).padStart(64, "0");
const cleanSig = auth.signature.toLowerCase().replace("0x", "");
const sigLen = (cleanSig.length / 2).toString(16).padStart(64, "0");
const paddedSig = cleanSig.padEnd(Math.ceil(cleanSig.length / 64) * 64, "0");
const txData = "0x" + methodId + recipient + quantity + authorizationId + deadline + offset + sigLen + paddedSig;
const contractAddress = auth.authMinter || "0xe78b4420ce205b8864f2f326f3181f9dd5ea8b5f";
// 5. Send transaction to wallet
console.log("🚀 Prompting wallet to sign and submit...");
const txHash = await window.ethereum.request({
method: "eth_sendTransaction",
params: [{
from: userAddress,
to: contractAddress,
data: txData,
value: "0x0",
gas: "0x7a120" // 500,000 gas limit
}]
});
console.log("🎉 Transaction sent successfully!");
console.log("Tx Hash:", txHash);
console.log(`Explorer link: https://eth-sepolia.blockscout.com/tx/${txHash}`);
alert(`Transaction submitted!\n\nTx Hash: ${txHash}`);
} catch (err) {
console.error("❌ Submission failed:", err);
alert(`Error: ${err.message || err}`);
}
})();
Public Last updated: 2026-11-05 10:10:50 AM