Skip to main content

Primary Sale

The PrimarySale smart contract extension is usable with any base smart contract. It lets you set a recipient for any sale value you collect in your smart contract.

Import

import "@thirdweb-dev/contracts/extension/PrimarySale.sol";

Available functionality

FunctionalityDescription
primarySaleRecipientReturns the primary sale recipient’s address.
setPrimarySaleRecipientLets an authorized wallet set primary sale recipient address.
_canSetPrimarySaleRecipientDefines the criteria a wallet must meet to be able to set primary sale recipient address.

Implementing the Contract extension

Import the contract extension and make your contract inherit it.

// 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;
}
}

Unlocked Features

On the dashboard, you'll be able to set the wallet address for the primary sale recipient under the Settings tab:

Batch Upload