Primary Sale
import "@thirdweb-dev/contracts/extension/PrimarySale.sol";
PrimarySale
lets you set a recipient for any sale value you intend to collect in your smart contract.
Availability in base contracts
The PrimarySale
extension is already available in the following base contracts:
- ERC20:
ERC20Drop
,ERC20SignatureMint
,ERC20DropVote
,ERC20SignatureMintVote
- ERC721:
ERC721Drop
,ERC721SignatureMint
- ERC1155:
ERC1155Drop
,ERC1155SignatureMint
Unlocked Features
Once deployed, you can use the features made available by these contracts on the SDK and dashboard:
Implementing the Contract extension
The PrimarySale
extension is an abstract contract, and expects you to implement the following functions by yourself:
Name | Type | Parameters | Returns | Description |
---|---|---|---|---|
_canSetPrimarySaleRecipient | internal view virtual | n/a | bool | Runs on every attempt to set a new primary sale recipient. Returns whether this info can be set in the given execution context. |
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/extension/PrimarySale.sol";
contract MyContract is PrimarySale {
/**
* We store the contract deployer's address only for the purposes of the example
* in the code comment below.
*
* Doing this is not necessary to use the `PrimarySale` extension.
*/
address public deployer;
constructor() {
deployer = msg.sender;
}
/**
* This function returns who is authorized to set primary sale recipient address for your contract.
*
* As an EXAMPLE, we'll only allow the contract deployer to set the primary sale recipient address.
*
* You MUST complete the body of this function to use the `PrimarySale` extension.
*/
function _canSetPrimarySaleRecipient()
internal
virtual
override
returns (bool)
{
return msg.sender == deployer;
}
}
Full API Reference
primarySaleRecipient
function primarySaleRecipient() public view returns (address);
- Returns the primary sale recipient address stored in the contract.
- Set this value using the
setPrimarySaleRecipient
function.
setPrimarySaleRecipient
function setPrimarySaleRecipient(address saleRecipient) external;
- Lets an authorized wallet set the primary sale recipient address.
- Parameter
saleRecipient
: The address to set as the new primary sale recipient. - The
_canSetPrimarySaleRecipient
function is run on every call to this function. If the return value of_canSetPrimarySaleRecipient
isfalse
, thesetPrimarySaleRecipient
call will revert.
_setupPrimarySaleRecipient
function _setupPrimarySaleRecipient(address saleRecipient) internal;
- Sets the primary sale recipient.
- Parameter
saleRecipient
: The address to set as the new primary sale recipient. - The
_canSetPrimarySaleRecipient
function is not run on a call to this function.
_canSetPrimarySaleRecipient
function _canSetPrimarySaleRecipient() internal view virtual returns (bool);
- Runs on every
setPrimarySaleRecipient
function call. - Returns whether a new primary sale recipient can be set in the given execution context.
- For example, this function can check whether the wallet calling
setPrimarySaleRecipient
is the contract owner, and enforce that only the current owner should be able to successfully callsetPrimarySaleRecipient
.