get user own tickets
This commit is contained in:
parent
08e8260cec
commit
26c2889c00
19
index.js
19
index.js
|
|
@ -66,12 +66,13 @@ app.get("/getBalance", async (request, response) => {
|
||||||
|
|
||||||
const privateKey = "0x5fa4fe1e676efae441cefb579f9af9fea37752e76a7ea99a873ce76df7a5a8e9";
|
const privateKey = "0x5fa4fe1e676efae441cefb579f9af9fea37752e76a7ea99a873ce76df7a5a8e9";
|
||||||
const baseTestnetProvider = new ethers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc");
|
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 utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider);
|
||||||
const erc1155Abi = [
|
const erc1155Abi = [
|
||||||
"function balanceOf(address account, uint256 id) view returns (uint256)",
|
"function balanceOf(address account, uint256 id) view returns (uint256)",
|
||||||
"function useTicket(address user, uint256 tournament_id) external",
|
"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);
|
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 });
|
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 });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user