get user own tickets

This commit is contained in:
Sewmina 2024-09-02 22:18:36 +05:30
parent 08e8260cec
commit 26c2889c00

View File

@ -66,12 +66,13 @@ app.get("/getBalance", async (request, response) => {
const privateKey = "0x5fa4fe1e676efae441cefb579f9af9fea37752e76a7ea99a873ce76df7a5a8e9";
const baseTestnetProvider = new ethers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc");
const ercContractAddress = "0xd66553eC8447E3589935503Beba046B729c04CEd";
const ercContractAddress = "0x21dfDE84E7F643697E8bBE5b9a97e8B0326775A8";
const utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider);
const erc1155Abi = [
"function balanceOf(address account, uint256 id) view returns (uint256)",
"function useTicket(address user, uint256 tournament_id) external",
"function startTournament(uint256 tournament_id) public"
"function startTournament(uint256 tournament_id) public",
"function getUserTickets(address user) public view returns (uint256[] memory)"
];
const contract = new ethers.Contract(ercContractAddress, erc1155Abi, utilWallet);
@ -136,3 +137,17 @@ app.get("/startTournament", async(request, response)=>{
response.status(500).json({ error: error.message });
}
})
app.get("/getMyTickets", async(request,response)=>{
const {address} = request.query;
if(!address){response.status(400).json({error:"address is required"})}
try{
const tx = await contract.getUserTickets(address);
const receipt = await tx.wait();
response.json({ transactionHash: receipt.transactionHash });
}catch(err){
console.error("Error reading tickets for user tourney:", err);
response.status(500).json({ error: err.message });
}
})