improved baby
This commit is contained in:
parent
1902df1f45
commit
08e8260cec
383
data.js
383
data.js
|
|
@ -1,9 +1,4 @@
|
||||||
export const gameDataABI = [
|
export const gameDataABI = [
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"stateMutability": "nonpayable",
|
|
||||||
"type": "constructor"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
|
@ -265,58 +260,6 @@ export const gameDataABI = [
|
||||||
"name": "URI",
|
"name": "URI",
|
||||||
"type": "event"
|
"type": "event"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "PP",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "uint256",
|
|
||||||
"name": "",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "SafeCoins",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "uint256",
|
|
||||||
"name": "",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "TOURNAMENT_TICKETS",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "uint256",
|
|
||||||
"name": "",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "TOURNAMENT_TROPHIES",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "uint256",
|
|
||||||
"name": "",
|
|
||||||
"type": "uint256"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
|
@ -328,41 +271,39 @@ export const gameDataABI = [
|
||||||
"internalType": "uint256",
|
"internalType": "uint256",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"type": "uint256"
|
"type": "uint256"
|
||||||
}
|
},
|
||||||
],
|
|
||||||
"name": "balanceOf",
|
|
||||||
"outputs": [
|
|
||||||
{
|
{
|
||||||
"internalType": "uint256",
|
"internalType": "uint256",
|
||||||
"name": "",
|
"name": "value",
|
||||||
"type": "uint256"
|
"type": "uint256"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateMutability": "view",
|
"name": "burn",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"internalType": "address[]",
|
"internalType": "address",
|
||||||
"name": "accounts",
|
"name": "account",
|
||||||
"type": "address[]"
|
"type": "address"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"internalType": "uint256[]",
|
"internalType": "uint256[]",
|
||||||
"name": "ids",
|
"name": "ids",
|
||||||
"type": "uint256[]"
|
"type": "uint256[]"
|
||||||
}
|
},
|
||||||
],
|
|
||||||
"name": "balanceOfBatch",
|
|
||||||
"outputs": [
|
|
||||||
{
|
{
|
||||||
"internalType": "uint256[]",
|
"internalType": "uint256[]",
|
||||||
"name": "",
|
"name": "values",
|
||||||
"type": "uint256[]"
|
"type": "uint256[]"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateMutability": "view",
|
"name": "burnBatch",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -378,43 +319,6 @@ export const gameDataABI = [
|
||||||
"stateMutability": "payable",
|
"stateMutability": "payable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"internalType": "address",
|
|
||||||
"name": "account",
|
|
||||||
"type": "address"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"internalType": "address",
|
|
||||||
"name": "operator",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "isApprovedForAll",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "bool",
|
|
||||||
"name": "",
|
|
||||||
"type": "bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "owner",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"internalType": "address",
|
|
||||||
"name": "",
|
|
||||||
"type": "address"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"inputs": [],
|
"inputs": [],
|
||||||
"name": "renounceOwnership",
|
"name": "renounceOwnership",
|
||||||
|
|
@ -506,6 +410,19 @@ export const gameDataABI = [
|
||||||
"stateMutability": "nonpayable",
|
"stateMutability": "nonpayable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "newOp",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "setOperator",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
|
@ -519,6 +436,218 @@ export const gameDataABI = [
|
||||||
"stateMutability": "nonpayable",
|
"stateMutability": "nonpayable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "tournament_id",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "startTournament",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "newOwner",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferOwnership",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "user",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "tournament_id",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "useTicket",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "withdraw",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "constructor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "account",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "id",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "balanceOf",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address[]",
|
||||||
|
"name": "accounts",
|
||||||
|
"type": "address[]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256[]",
|
||||||
|
"name": "ids",
|
||||||
|
"type": "uint256[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "balanceOfBatch",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256[]",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "getExpiredTournaments",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256[]",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "tournamentId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "getTournamentParticipants",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address[]",
|
||||||
|
"name": "",
|
||||||
|
"type": "address[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "account",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "operator",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "isApprovedForAll",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "operator",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "owner",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "PP",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "SafeCoins",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
|
@ -552,16 +681,29 @@ export const gameDataABI = [
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [],
|
||||||
|
"name": "TOURNAMENT_TICKETS",
|
||||||
|
"outputs": [
|
||||||
{
|
{
|
||||||
"internalType": "address",
|
"internalType": "uint256",
|
||||||
"name": "newOwner",
|
"name": "",
|
||||||
"type": "address"
|
"type": "uint256"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name": "transferOwnership",
|
"stateMutability": "view",
|
||||||
"outputs": [],
|
"type": "function"
|
||||||
"stateMutability": "nonpayable",
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "TOURNAMENT_TROPHIES",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -582,12 +724,5 @@ export const gameDataABI = [
|
||||||
],
|
],
|
||||||
"stateMutability": "pure",
|
"stateMutability": "pure",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
|
||||||
{
|
|
||||||
"inputs": [],
|
|
||||||
"name": "withdraw",
|
|
||||||
"outputs": [],
|
|
||||||
"stateMutability": "nonpayable",
|
|
||||||
"type": "function"
|
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
52
index.js
52
index.js
|
|
@ -66,11 +66,12 @@ 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 = "0x1562aA47cab3Bbf4689D4cBB352e01d7A954EF37";
|
const ercContractAddress = "0xd66553eC8447E3589935503Beba046B729c04CEd";
|
||||||
const utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider);
|
const utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider);
|
||||||
const erc1155Abi = [
|
const erc1155Abi = [
|
||||||
// Only include the methods you need, for brevity we'll just include balanceOf
|
"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 startTournament(uint256 tournament_id) public"
|
||||||
];
|
];
|
||||||
const contract = new ethers.Contract(ercContractAddress, erc1155Abi, utilWallet);
|
const contract = new ethers.Contract(ercContractAddress, erc1155Abi, utilWallet);
|
||||||
|
|
||||||
|
|
@ -89,4 +90,49 @@ app.get("/getTickets", async (request, response)=>{
|
||||||
console.error("Error fetching balance:", error);
|
console.error("Error fetching balance:", error);
|
||||||
response.status(500).json({ error: "Internal server error" });
|
response.status(500).json({ error: "Internal server error" });
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/getOperatorAddress", async (request, response) => {
|
||||||
|
response.send(utilWallet.address);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/useTicket", async (request, response) => {
|
||||||
|
const { address, tournamentId } = request.query;
|
||||||
|
|
||||||
|
if (!address || !tournamentId) {
|
||||||
|
return response.status(400).json({ error: "address and tournamentID are required" });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Send a transaction to the `useTicket` function
|
||||||
|
const tx = await contract.useTicket(address, tournamentId);
|
||||||
|
|
||||||
|
// Wait for the transaction to be mined
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
response.json({ transactionHash: receipt.transactionHash });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error using ticket:", error);
|
||||||
|
response.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/startTournament", async(request, response)=>{
|
||||||
|
const {tournamentId} = request.query;
|
||||||
|
if(!tournamentId){
|
||||||
|
return response.status(400).json({ error: "tournamentID is required" });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Send a transaction to the `useTicket` function
|
||||||
|
const tx = await contract.startTournament(tournamentId);
|
||||||
|
|
||||||
|
// Wait for the transaction to be mined
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
response.json({ transactionHash: receipt.transactionHash });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error expiring tourney:", error);
|
||||||
|
response.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user