Staking ERC721 Base
import "@thirdweb-dev/contracts/base/Staking721Base.sol";
The Staking721Base
smart contract implements an NFT staking mechanism. It creates a composition of an NFT Collection and an ERC20 Token contract into a staking mechanism.
The base contract provides an implementation of staking logic. Contract admins can implement their own reward mechanisms by overriding existing functions.
Detected Extensions
Once deployed, you can use the features made available by these extensions on the SDK and dashboard:
Click on each feature to learn more about what functions are available.
Usage
Import the contract and inherit from it.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/Staking721Base.sol";
contract MyContract is Staking721Base {
constructor(
address _defaultAdmin,
uint256 _timeUnit,
uint256 _rewardsPerUnitTime,
address _stakingToken,
address _rewardToken,
address _nativeTokenWrapper
) Staking721Base(_defaultAdmin, _timeUnit, _rewardsPerUnitTime, _stakingToken, _rewardToken, _nativeTokenWrapper) {}
}
Functions to Override
The following functions have been implemented on this contract & are available to be overridden to add custom logic:
mintRewards
/**
* @dev Mint ERC20 rewards to the staker. Must override.
*
* @param _staker Address for which to calculated rewards.
* @param _rewards Amount of tokens to be given out as reward.
*
*/
function _mintRewards(address _staker, uint256 _rewards) internal virtual override {
// Mint or transfer reward-tokens here.
// e.g.
//
// IERC20(rewardToken).transfer(_staker, _rewards);
//
// OR
//
// Use a mintable ERC20, such as thirdweb's `TokenERC20.sol`
//
// TokenERC20(rewardToken).mintTo(_staker, _rewards);
// note: The staking contract should have minter role to mint tokens.
}