StackAsk is a community where developers ask questions, share answers and learn from each others real-world experience, so every solved problem helps the next person who runs into it.
// contracts/KeepPromise.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC721.sol"; import "./../../utils/Counters.sol"; struct Promise { uint256 _id; string _promise; string _deadline; string _punishment; address _punisher; } contract KeepPromise is ERC721 { using Counters for Counters.Counter; Counters.Counter private _promiseIds; mapping(uint256 => Promise) private _promises; mapping(address => string) private _playerNickNames; constructor() public ERC721("Promise", "PRM") {} function join(string memory pNickName) public returns(string memory) { address player = msg.sender; require(_notJoined(player), "KeepPromise: you've already joined game"); _playerNickNames[player] = pNickName; return string(abi.encodePacked("SUCCESS: ", pNickName)); } function submitPromise( string memory pPromise, string memory pDeadline, string memory pPunishment, address pPunisher ) public returns (uint256) { address player = msg.sender; require(_joined(player), "KeepPromise: you've not joined game yet"); require(_joined(pPunisher), "KeepPromise: the Punisher's not joined game yet"); _promiseIds.increment(); uint256 newPromiseId = _promiseIds.current(); _mint(player, newPromiseId); Promise memory prom = Promise(newPromiseId, pPromise, pDeadline, pPunishment, pPunisher); _addPromise(newPromiseId, prom); return newPromiseId; } function getPromise(uint256 pPromiseId) public view returns(Promise memory) { address player = msg.sender; require(_joined(player), "KeepPromise: you've not joined game yet"); return _promises[pPromiseId]; } function getNickName() public view returns(string memory) { address player = msg.sender; return _playerNickNames[player]; } function getPlayerNickName(address pPlayer) public view returns(string memory) { return _playerNickNames[pPlayer]; } function _addPromise(uint256 pPromiseId, Promise memory pPromise) internal virtual { _promises[pPromiseId] = pPromise; } function _joined(address pPlayer) internal view virtual returns (bool) { return bytes(_playerNickNames[pPlayer]).length != 0; } function _notJoined(address pPlayer) internal view virtual returns (bool) { return bytes(_playerNickNames[pPlayer]).length == 0; } }
let contract = await KeepPromise.deployed() contract.join("Dzung") contract.getNickName(); contract.submitPromise("Love myself", "2021-12-12", "Love Her", "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f") contract.getPromise(1);
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Your account is signed in on the device(s) below. Sign out of at least one of them to continue signing in on this device.
Your account is signed in on the device(s) below. Sign out directly on one of those devices, or wait until the sign-in again time shown below.
If you cant access those devices, please contact the administrator to sign them out for you.
Input your email to receive reset password link, or if you remember your password, you can click