Launch A Token

newTokenV2

To Launch a new token, you send a transaction to call the newTokenV2 method:

// solidity interface 

/// @notice Create a new token (V2) with flexible parameters
/// @param params The parameters for the new token
/// @return token The address of the created token
function newTokenV2(NewTokenV2Params calldata params) external payable returns (address token); 


/// @notice Parameters for creating a new token (V2)
struct NewTokenV2Params {
    /// The name of the token
    string name;
    /// The symbol of the token
    string symbol;
    /// The ipfs cid of the metadata 
    string meta;
    /// The DEX supply threshold type
    DexThreshType dexThresh;
    /// The salt for deterministic deployment
    bytes32 salt;
    /// The tax rate in basis points (if non-zero, this is a tax token)
    uint16 taxRate;
    /// The migrator type (see MigratorType enum)
    MigratorType migratorType;
    /// The quote token address (native gas token if zero address)
    address quoteToken;
    /// The initial quote token amount to spend for buying
    uint256 quoteAmt;
    /// The beneficiary address for the token
    /// For rev share tokens, this is the address that can claim the LP fees
    /// For tax tokens, this is the address that receives the tax fees
    address beneficiary;
    /// The optional permit data for the quote token
    bytes permitData;
}



/// @notice the migrator type
/// @dev the migrator type determines how the liquidity is added to the DEX.
/// Note: To mitigate the risk of DOS, if a V3 migrator is used but the liquidity cannot
/// be added to v3 pools, the migrator will fallback to a V2 migrator.
enum MigratorType {
    V3_MIGRATOR, // Migrate the liquidity to a Uniswap V3 like pool
    V2_MIGRATOR // Migrate the liquidity to a Uniswap V2 like pool
}

/// @dev dex threshold types
enum DexThreshType {
    TWO_THIRDS, //  66.67% supply
    FOUR_FIFTHS, // 80% supply
    HALF, // 50% supply
    _95_PERCENT, // 95% supply
    _81_PERCENT, // 81% supply
    _1_PERCENT // 1% supply => mainly for testing

}

The new newTokenV2 method takes a single struct (or tuple in solidity’s jargon) as its input. Let’s explain some fields of the NewTokenV2Params struct:

  • meta : this is the ipfs cid you get from last section , eg, bafkreicwlkpvrcqg4bbhyp2fnhdwbqos5ghka6gdjra3tdkgxxs74hqsze

  • dexThresh : This determines the threshold to migrate token to DEX. Our UI uses FOUR_FIFTHS by default, which means when 80% or more of the total supply has been sold from the bonding curve , the token will be migrated to DEX.

  • taxRate : since v3.3.0, we support creating a tax token. The tax is only applied for the first 30days after the token being migrated to DEX. The maximum tax rate is 10%

  • migratorType : The migrator for the token. Note, if a token has tax, it can only be migrated to a V2 pool, which means only a V2_MIGRATOR is allowed for a tax token. For other tokens, it is recommended to use a V3_MIGRATOR. With a V3_MIGRATOR we will optimize your liquidity and enable the revenue share feature for you token.

  • quoteToken : The quote token you want to use. When your quote token is the native gas token (i.e ETH or BNB), leave quoteToken as the zero address. Note: only enabled quoteToken can be used.

  • quoteAmt: The amount of quoteToken you want to spend to buy token on creation.

  • beneficiary : If the token has not TAX and using a V3_MIGRATOR , the rev share fees can be claimed with this address; If the token has TAX, this address will receive the tax fee.

  • permitData : If your quoteToken is not zero address (i.e, not native gas token ETH or BNB, but some ERC20 token). You can construct the permitData to avoid another approve TX. Check our example below to see how to construct the permitData.

  • salt : The salt is mandate. All tokens created from the newTokenV2 method have a vanity ending. If the token has no tax, it has an ending of 8888 or it has an ending of 7777.

Here is an example script for generating the salt:

  • The suffix is 8888 if your token has not tax, otherwise it is 7777

  • The token impl address is :

    • 0x8B4329947e34B6d56D71A3385caC122BaDe7d78D for non tax token

    • 0x5dd913731C12aD8DF3E574859FDe45412bF4aaD9 for tax token

  • Portal address on BSC is 0xe2cE6ab80874Fa9Fa2aAE65D277Dd6B8e65C9De0


/// get vanity token address and salt 
async function findVanityTokenSalt(suffix: string, token_impl: Address, portal: Address) {
    if (suffix.length !== 4) {
        throw new Error("Suffix must be exactly 4 characters");
    }

    // predict the vanity token address based on the saltå
    const predictVanityTokenAddress = (salt: Hex): Address => {
        const bytecode = '0x3d602d80600a3d3981f3363d3d373d3d3d363d73'
            + token_impl.slice(2).toLowerCase() // remove 0x prefix
            + '5af43d82803e903d91602b57fd5bf3' as Hex;

        return getContractAddress({
            from: portal,
            salt: toBytes(salt),
            bytecode,
            opcode: "CREATE2",
        });
    }

    // Note: you don't have to use a private key as the starting seed, you can use 
    // any pseudo-random string as the starting seed. 
    // 
    // Here, we use a random private key as the starting seed
    // Then repeatedly hash the seed until we get the vanity address
    const seed = generatePrivateKey();
    let salt = keccak256(toHex(seed));
    let iterations = 0; // Track the number of iterations 

    while (!predictVanityTokenAddress(salt).endsWith(suffix)) {
        salt = keccak256(salt);
        iterations++; // Increment the iteration count
    }

    console.log(`Iterations: ${iterations}`); // Print the number of iterations

    return {
        salt,
        address: predictVanityTokenAddress(salt),
    }
}

In the above example script, we using a random private key as the seed. In reality, you can use any random number or string as your seed to find the salt.

Legacy Methods (Deprecatd)

To launch a new token, you call the newToken function of our portal contract.

    /// @notice Create a new meme token
    /// @param name  The name of the token
    /// @param symbol  The symbol of the token
    /// @param meta  The metadata ipfs cid of the token
    /// @dev if msg.value is not zero, the caller would be the initial buyer of the token
    function newToken(string calldata name, string calldata symbol, string calldata meta)
        external
        payable
        returns (address token);

To launch a token with the "revenue share" enabled, you call the newVanityToken function of our portal contract:

    /// @notice Create a new vanity token
    /// @param name The name of the token
    /// @param symbol The symbol of the token
    /// @param meta The metadata URI of the token
    /// @param salt The salt for deterministic deployment
    /// @param beneficiary The address of the beneficiary
    /// @return token The address of the created token
    function newVanityToken(
        string calldata name,
        string calldata symbol,
        string calldata meta,
        bytes32 salt,
        address beneficiary
    ) external payable returns (address token);

The vanity token must end with "8888" , you must find a possible salt to satisfy this condition. Here is an example typescript to find such a salt:

import { Address, getContractAddress, Hex,  keccak256,toBytes, toHex } from 'viem';
import { generatePrivateKey } from 'viem/accounts';

// BSC mainent token implementation address
const TOKEN_IMPLEMENTATION_ADDDRESS = "0x8b4329947e34b6d56d71a3385cac122bade7d78d";
// BSC mainnet portal address
const PORTAL_ADDRESS = "0xe2cE6ab80874Fa9Fa2aAE65D277Dd6B8e65C9De0" as Address;

/// get vanity token address and salt 
export async function findSalt(){

    // predict the vanity token address based on the salt
    const predictVanityTokenAddress = (salt: Hex):Address => {
        const bytecode = '0x3d602d80600a3d3981f3363d3d373d3d3d363d73'  
            + TOKEN_IMPLEMENTATION_ADDDRESS.slice(2).toLowerCase() // remove 0x prefix
            + '5af43d82803e903d91602b57fd5bf3' as Hex;
                 
        return getContractAddress({
            from: PORTAL_ADDRESS,
            salt: toBytes(salt),
            bytecode,
            opcode: "CREATE2",
        });
    }

    // the starting seed is a random string (you can use anyting, e.g: UUID, timestamp , etc)
    // Here, we use a random private key as the starting seed. 
    // Then repetively hash the seed until we find a salt that ends with 8888
    const seed = generatePrivateKey();
    let salt = keccak256(toHex(seed));

    while (!predictVanityTokenAddress(salt).endsWith("8888")) {
        salt = keccak256(salt);
    }

   

    return salt;
}

Events

Whenever a new token is created, a TokenCreated event would emitted from our Portal contract:

/// @notice emitted when a new token is created
///
/// @param ts The timestamp of the event
/// @param creator The address of the creator
/// @param nonce The nonce of the token
/// @param token  The address of the token
/// @param name  The name of the token
/// @param symbol  The symbol of the token
/// @param meta The meta URI of the token
event TokenCreated(
    uint256 ts, address creator, uint256 nonce, address token, string name, string symbol, string meta
);

Last updated