Spaces:
Runtime error
Runtime error
| try { | |
| showStatus('Preparing swap...'); | |
| const router = new ethers.Contract(CONFIG.ROUTER_ADDRESS, ROUTER_ABI, signer); | |
| // NOTE: In production use WBNB address and proper path. Here we use placeholder. | |
| const WBNB = '0xBB4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'; // mainnet WBNB (demo) — replace for testnet if needed | |
| const path = [WBNB, CONFIG.TOKEN_ADDRESS]; | |
| const deadline = Math.floor(Date.now() / 1000) + 60 * 10; | |
| const amountIn = ethers.utils.parseEther('0.05'); | |
| const tx = await router.swapExactETHForTokens(0, path, account, deadline, { value: amountIn }); | |
| showStatus('Swap tx sent: ' + tx.hash); | |
| await tx.wait(); | |
| showStatus('Swap confirmed: ' + tx.hash); | |
| window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank'); | |
| } catch (e) { console.error(e); showStatus('Swap failed: ' + (e.message || e)); } | |
| }; | |
| // Add liquidity | |
| addLPBtn.onclick = async () => { | |
| try { | |
| showStatus('Adding liquidity...'); | |
| const router = new ethers.Contract(CONFIG.ROUTER_ADDRESS, ROUTER_ABI, signer); | |
| const token = new ethers.Contract(CONFIG.TOKEN_ADDRESS, TOKEN_ABI, signer); | |
| const tokenAmount = ethers.utils.parseUnits('1000', 18); | |
| const ethAmount = ethers.utils.parseEther('0.05'); | |
| const approveTx = await token.approve(CONFIG.ROUTER_ADDRESS, tokenAmount); | |
| showStatus('Approve tx: ' + approveTx.hash); | |
| await approveTx.wait(); | |
| const deadline = Math.floor(Date.now() / 1000) + 60 * 10; | |
| const tx = await router.addLiquidityETH(CONFIG.TOKEN_ADDRESS, tokenAmount, 0, 0, account, deadline, { value: ethAmount }); | |
| showStatus('AddLiquidity tx sent: ' + tx.hash); | |
| await tx.wait(); | |
| showStatus('Liquidity added: ' + tx.hash); | |
| window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank'); | |
| } catch (e) { console.error(e); showStatus('Add liquidity failed: ' + (e.message || e)); } | |
| }; | |
| // Stake LP (demo) | |
| stakeLPBtn.onclick = async () => { | |
| try { | |
| showStatus('Staking LP...'); | |
| const staking = new ethers.Contract(CONFIG.STAKING_ADDRESS, STAKING_ABI, signer); | |
| const amount = ethers.utils.parseUnits('1', 18); // stake 1 LP (demo) | |
| const tx = await staking.stake(amount); | |
| showStatus('Stake tx sent: ' + tx.hash); | |
| await tx.wait(); | |
| showStatus('Stake confirmed: ' + tx.hash); | |
| window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank'); | |
| } catch (e) { console.error(e); showStatus('Stake failed: ' + (e.message || e)); } | |
| }; | |
| // Refresh balances (demo) | |
| refreshBtn.onclick = async () => { | |
| try { | |
| if (!pr |