- 
      
 - 
        
Save korrio/19bc1e921da3058830ea0d5254c08ef1 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
Chmarusso created this gist
Feb 13, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol"; contract NftStaker { IERC1155 public parentNFT; struct Stake { uint256 tokenId; uint256 amount; uint256 timestamp; } // map staker address to stake details mapping(address => Stake) public stakes; // map staker to total staking time mapping(address => uint256) public stakingTime; constructor() { parentNFT = IERC1155(0xd9145CCE52D386f254917e481eB44e9943F39138); // Change it to your NFT contract addr } function stake(uint256 _tokenId, uint256 _amount) public { stakes[msg.sender] = Stake(_tokenId, _amount, block.timestamp); parentNFT.safeTransferFrom(msg.sender, address(this), _tokenId, _amount, "0x00"); } function unstake() public { parentNFT.safeTransferFrom(address(this), msg.sender, stakes[msg.sender].tokenId, stakes[msg.sender].amount, "0x00"); stakingTime[msg.sender] += (block.timestamp - stakes[msg.sender].timestamp); delete stakes[msg.sender]; } function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4) { return bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")); } }