Launching
const handleLaunch = async () => {
if (!walletAddress) {
setError('Please connect your wallet first')
return
}
if (!formData.agentName || !formData.tokenName || !formData.tokenSymbol || !coinImage) {
setError('Please fill in all required fields and upload an image')
return
}
setLaunching(true)
setError('')
try {
const { ethers } = await import('ethers')
const provider = new ethers.BrowserProvider(window.ethereum)
const signer = await provider.getSigner()
// Upload metadata to IPFS
const metadata = JSON.stringify({
name: formData.agentName,
description: formData.personality || `${formData.agentName} AI Agent Token`,
image: coinImageHash,
external_url: formData.website || '',
attributes: [
{ trait_type: 'Personality', value: formData.personality || 'Not specified' },
{ trait_type: 'Creator', value: walletAddress },
{ trait_type: 'Launch Date', value: new Date().toISOString() }
]
})
const metadataResponse = await fetch('https://api.pinata.cloud/pinning/pinJSONToIPFS', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${PINATA_JWT}`
},
body: JSON.stringify({ pinataContent: JSON.parse(metadata) })
})
const { IpfsHash } = await metadataResponse.json()
const metadataURI = `ipfs://${IpfsHash}`
// Interact with contract
const contract = new ethers.Contract(LAUNCHPAD_ADDRESS, LAUNCHPAD_ABI, signer)
const launchFee = ethers.parseEther('0.001')
const initialBuy = ethers.parseEther(formData.initialBuyBNB || '0')
const totalValue = launchFee + initialBuy
const tx = await contract.launchAgent(
formData.tokenName,
formData.tokenSymbol,
`agent_${Date.now()}`,
metadataURI,
ethers.parseEther('0.0001'),
ethers.parseEther('1000000000'),
ethers.parseEther('18'),
{ value: totalValue }
)
await tx.wait()
setSuccess(true)
} catch (error: any) {
setError(error.message || 'Failed to launch token')
}
setLaunching(false)
}Last updated