diff --git a/packages/client/src/mud/createSystemCalls.ts b/packages/client/src/mud/createSystemCalls.ts index 867e66a3..e13fc285 100644 --- a/packages/client/src/mud/createSystemCalls.ts +++ b/packages/client/src/mud/createSystemCalls.ts @@ -38,8 +38,8 @@ export function createSystemCalls( await waitForTransaction(tx); } - const transfer = async (transferData: any) => { - const tx = await worldContract.write.transfer([...transferData]); + const transfer = async (addr: any, transferData: any) => { + const tx = await worldContract.write.transfer([addr, ...transferData]); await waitForTransaction(tx); } diff --git a/packages/client/src/pages/test/index.jsx b/packages/client/src/pages/test/index.jsx index 47312a47..7f9c16cc 100644 --- a/packages/client/src/pages/test/index.jsx +++ b/packages/client/src/pages/test/index.jsx @@ -11,14 +11,12 @@ import { getRandomStr } from '../../utils/utils'; import './index.scss'; const abi = [{"inputs":[{"internalType":"uint256","name":"_waitBlockCount","type":"uint256"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_notRevealedInfo","type":"string"},{"internalType":"string","name":"_revealedDesc","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"randomId","type":"uint256"},{"indexed":false,"internalType":"address","name":"author","type":"address"}],"name":"NewRandom","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"randomList","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"address","name":"author","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"revealNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"userList","outputs":[{"internalType":"uint256","name":"randomId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"HP","type":"uint256"},{"internalType":"uint256","name":"Attack","type":"uint256"},{"internalType":"uint256","name":"AttackRange","type":"uint256"},{"internalType":"uint256","name":"Speed","type":"uint256"},{"internalType":"uint256","name":"Strength","type":"uint256"},{"internalType":"uint256","name":"Space","type":"uint256"},{"internalType":"enum MRandom.RandomState","name":"state","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"waitBlockCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] -const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3' -const rpc = 'http://127.0.0.1:8545' const Test = () => { const [stepData, setStepData] = useState([]); const [transferData, setTransferData] = useState([]); const [battleData, setBattleData] = useState([]); - const [confirmBattleData, setConfirmBattleData] = useState(['Attack', 1]); + const [confirmBattleData, setConfirmBattleData] = useState(['attack', 1]); const [battlesData, setBattlesData] = useState([]); const [boxData, setBoxData] = useState([]); const [boxId, setBoxId] = useState([]); @@ -99,10 +97,10 @@ const Test = () => { const mintFun = () => { let privateKey = network.privateKey - let provider = new ethers.providers.JsonRpcProvider(rpc) + let provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545') let wallet = new ethers.Wallet(privateKey, provider) console.log(wallet) - let userContractAddress = contractAddress + let userContractAddress = '0x2498e8059929e18e2a2cED4e32ef145fa2F4a744' let userContract = new ethers.Contract(userContractAddress, abi, wallet) console.log(userContract) userContract.mint().then(async res => { @@ -116,10 +114,10 @@ const Test = () => { const revealNFTFun = () => { let privateKey = network.privateKey - let provider = new ethers.providers.JsonRpcProvider(rpc) + let provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545') let wallet = new ethers.Wallet(privateKey, provider) console.log(wallet) - let userContractAddress = contractAddress + let userContractAddress = '0x2498e8059929e18e2a2cED4e32ef145fa2F4a744' let userContract = new ethers.Contract(userContractAddress, abi, wallet) userContract.revealNFT(revealNFTData).then(async res => { console.log(res) @@ -194,7 +192,7 @@ const Test = () => { const transferPlayer = () => { console.log(transferData, 'transfer') - transfer(transferData); + transfer(account, transferData); } const battleInvitationFun = () => { @@ -289,6 +287,7 @@ const Test = () => {
用户信息 {item.isMe ? '(自己)' : ''}
addr: {item.addr}
hp: {item.hp.toString()}
+
attack: {item.attack.toString()}
oreBalance: {item.oreBalance.toString()}
treasureBalance: {item.treasureBalance.toString()}
坐标:{item?.x || 0},{item?.y || 0}
@@ -388,9 +387,9 @@ const Test = () => {
攻击策略