Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Token Sale
copy icon
t1nyTi
• version 1.0.0
Token
ERC20
Sale

Token Sale

Token sale which allows users to buy an ERC20 using a different ERC20. Owner is able to adjust both tokens, and the exchange rate between the two.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

t1nyTi

Recent Use

🍞 0x760D saved
🥐 0x9cb3 downloaded
🥖 0xE5a8 downloaded

Last Publish

10/17/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
totalSupply() :
totalSupply(): This function returns the total supply of tokens that have been created. It works by accessing the total supply of tokens stored in the smart contract and returning the value.balanceOf(address account): This function returns the balance of tokens held by a given account. It works by accessing the balance of tokens stored in the smart contract for the given account and returning the value.transfer(address recipient, uint256 amount): This function transfers a given amount of tokens from the sender to the recipient. It works by subtracting the amount from the sender's balance and adding it to the recipient's balance.allowance(address owner, address spender): This function returns the amount of tokens that the owner (autogenerated documentation)
balanceOf(address) :
balanceOf: This function returns the balance of a given account. It takes an address as an argument and returns the balance of that account as a uint256.transfer: This function transfers a specified amount of tokens from one account to another. It takes two arguments, the recipient address and the amount of tokens to be transferred, and returns a boolean indicating whether the transfer was successful.allowance: This function returns the amount of tokens that an owner has allowed a spender to transfer from their account. It takes two arguments, the owner address and the spender address, and returns the amount of tokens as a uint256.approve: This function allows an owner to approve a spender to transfer a specified (autogenerated documentation)
transfer(address,uint256) :
function name() external view returns (string memory);This function returns the name of the token as a string. It is an external view function, meaning that it does not modify the state of the contract and can be called by anyone. (autogenerated documentation)
allowance(address,address) :
function name() external view returns (string memory);This function returns the name of the ERC20 token. It is a view function, meaning it does not modify the state of the contract and does not cost any gas. (autogenerated documentation)
approve(address,uint256) :
This function allows a spender to approve a certain amount of tokens to be transferred from the owner's account to the spender's account. The function returns a boolean value indicating whether the approval was successful or not. The function also emits two events, Transfer and Approval, which are indexed by the from and to addresses, and the value of the transfer. (autogenerated documentation)
transferFrom(address,address,uint256) :
transferFrom() allows a user to transfer a specified amount of tokens from one address to another. It requires the sender address, recipient address, and the amount of tokens to be transferred. It returns a boolean value indicating whether the transfer was successful or not. It also emits two events, Transfer and Approval, which are used to track the transfer of tokens. The Transfer event logs the from address, to address, and the amount of tokens transferred. The Approval event logs the owner address, spender address, and the amount of tokens approved. (autogenerated documentation)
name() :
This function is part of the SafeERC20 library, which provides a set of functions that allow developers to interact with ERC20 tokens in a secure and safe manner. The name() function returns the name of the ERC20 token, the symbol() function returns the symbol of the token, and the decimals() function returns the number of decimals used by the token. All of these functions are view functions, meaning that they do not modify the state of the blockchain and can be called without any gas costs. (autogenerated documentation)
symbol() :
This function is part of the SafeERC20 library, which provides a set of functions that allow developers to create and interact with ERC20 tokens in a secure manner. The symbol() function returns a string representing the symbol of the token, while the decimals() function returns an unsigned 8-bit integer representing the number of decimal places used by the token. Both of these functions are view functions, meaning that they do not modify the state of the blockchain and can be called without any gas costs. (autogenerated documentation)
decimals() :
This function returns the number of decimals used to represent a token's value. It works by accessing the public variable "decimals" which is declared in the ERC20 interface and returns the value stored in that variable. (autogenerated documentation)
safeTransfer(address,uint256) :
This function is an internal function that facilitates the transfer of a specified amount of a given ERC20 token from the contract to a specified address. It does this by encoding the transfer function of the token contract with the specified address and value, and then calling the encoded function with an optional return. (autogenerated documentation)
safeTransferFrom(address,address,uint256) :
This function is an internal function that allows for the transfer of tokens from one address to another. It takes four parameters: an IERC20 token, the address of the sender, the address of the recipient, and the amount of tokens to be transferred. It then encodes the transferFrom function of the token with the given parameters and calls it with an optional return. This allows for the transfer of tokens from one address to another without the need for a transaction. (autogenerated documentation)
safeApprove(address,uint256) :
This function is used to approve a certain amount of tokens to a spender. It is an internal function that is used to ensure that the allowance from a non-zero to a non-zero allowance is not allowed. It does this by first checking that the value is either 0 or that the token allowance from the address of this to the spender is 0. If this is true, it then calls the token's approve function with the spender and the value as parameters. (autogenerated documentation)
safeIncreaseAllowance(address,uint256) :
This function is used to increase the allowance of a given spender for a given ERC20 token. It does this by first calculating the new allowance by adding the given value to the existing allowance. It then calls the approve function of the token contract, passing in the spender address and the new allowance as parameters. The _callOptionalReturn function is used to ensure that the transaction is executed successfully. (autogenerated documentation)
safeDecreaseAllowance(address,uint256) :
This function is used to safely decrease the allowance of a given token for a given spender. It does this by first calculating the new allowance by subtracting the given value from the current allowance. It then calls the token's approve function with the spender and new allowance as parameters. If the allowance is decreased below zero, an error is thrown. (autogenerated documentation)
_callOptionalReturn() :
This function is used to make a low-level call to an ERC20 token contract. It takes in two parameters, an IERC20 token and a bytes memory data. The function then calls the token's functionCall method, passing in the data and a string indicating that the call failed. If the call returns a non-zero length byte array, the function then uses the ABI to decode the return data and check if the operation was successful. If the operation was not successful, an error is thrown. (autogenerated documentation)
Call() :
This function is used to make a low-level call to an ERC20 token contract. It takes in two parameters, data and a boolean. The data parameter is used to pass in the data needed to make the call, such as the function name and the parameters. The boolean is used to indicate whether the call should be successful or not. The function then uses the ABI to decode the return data from the call and checks if the call was successful. If the call was successful, it returns the decoded data. (autogenerated documentation)
isContract(address) :
This function checks if an Ethereum address is a contract or not. It does this by comparing the codehash of the address to a known hash of an empty account. If the codehash is not equal to the empty account hash and is not equal to 0x0, then the address is a contract. The codehash is obtained by using the extcodehash opcode. (autogenerated documentation)
sendValue(address,uint256) :
This function is used to send a specified amount of Ether from the contract's balance to a specified recipient address. It first checks to make sure that the contract has enough balance to cover the amount being sent. If it does, it then calls the recipient address with the specified amount of Ether as the value. If the call is successful, the Ether is sent to the recipient address. (autogenerated documentation)
functionCall(address) :
This function is an internal function that is used to call a function at a given address with a given data payload. It returns a bytes memory object containing the result of the call. The function works by using the low-level call instruction to call the target address with the given data payload. If the call fails, an error message is returned. (autogenerated documentation)
functionCall(address,string) :
This function is an internal function that is used to call a function on a given address with a given data payload. It takes in an address, a bytes memory data, and a string memory errorMessage as parameters. It then calls the _functionCallWithValue function, passing in the target address, data, 0, and errorMessage. This function returns a bytes memory. (autogenerated documentation)
CallWithValue() :
This function is used to call a function on a given address with a given data payload and a given value. It works by encoding the given data payload into a call data payload, and then sending a transaction to the given address with the call data payload and the given value. The function then returns the result of the call as a bytes memory. (autogenerated documentation)
functionCallWithValue(address,uint256) :
This function is an internal function that is used to call a target address with a given data payload and a specified value. It returns a bytes memory object. It works by first checking if the call to the target address was successful, and if not, it throws an error message. If the call was successful, it returns the bytes memory object. (autogenerated documentation)
functionCallWithValue(address,uint256,string) :
This function is an internal function that is used to call a function on a target address with a specified value. It first checks to make sure that the address calling the function has enough balance to cover the value, and if so, it calls the _functionCallWithValue function with the target address, data, value, and an error message. The _functionCallWithValue function then returns the data as a byte array. (autogenerated documentation)
_functionCallWithValue(address,uint256,string) :
This function is used to call a contract with a specified value. It takes in an address of the target contract, data to be sent to the contract, the value to be sent, and an error message. It first checks if the target address is a contract, and if it is, it calls the contract with the specified value and data. If the call is successful, it returns the data returned by the contract. If the call is unsuccessful, it either reverts with the data returned by the contract or with the specified error message. (autogenerated documentation)
add(uint256,uint256) :
This function adds two uint256 values together and returns the result. It uses a require statement to ensure that the result of the addition does not exceed the maximum value of a uint256. If the addition does exceed the maximum value, an error is thrown. (autogenerated documentation)
sub(uint256,uint256) :
This function is an internal function that performs subtraction of two uint256 values. It takes two uint256 values, a and b, as parameters and returns the difference between them as a uint256 value. It also includes a safety check to prevent overflow, which will throw an error if the result of the subtraction is less than 0. (autogenerated documentation)
sub(uint256,uint256,string) :
This function is an internal pure function that subtracts two uint256 values and returns the result. It requires that the second value (b) is less than or equal to the first value (a). If this is not the case, an error message is thrown. The function then subtracts the two values and returns the result. (autogenerated documentation)
mul(uint256,uint256) :
This function is an internal function that multiplies two uint256 numbers and returns the result. It first checks if the first number is 0, and if so, it returns 0. Otherwise, it multiplies the two numbers and checks if the result is valid by dividing the result by the first number and comparing it to the second number. If the result is valid, it returns the result, otherwise it throws an error. (autogenerated documentation)
div(uint256,uint256) :
This function is an internal function that performs a division operation on two unsigned 256-bit integers (uint256). It takes two parameters, a and b, and returns the result of a divided by b. If b is equal to zero, it will throw an error message ("SafeMath: division by zero"). This function uses a recursive approach to calculate the result of the division. It starts by checking if b is equal to zero, and if it is, it throws an error. Otherwise, it will divide a by 2 and call the function again with the new parameters (a/2 and b). This process is repeated until b is greater than a, at which point the result is returned. (autogenerated documentation)
div(uint256,uint256,string) :
This function is an internal pure function that takes in three parameters: a, b, and an error message. It divides a by b and returns the result. It also requires that b is greater than 0, and if it is not, it will throw an error with the error message provided. (autogenerated documentation)
mod(uint256,uint256) :
This function is an internal pure function that calculates the modulo of two unsigned 256-bit integers (a and b). It returns the remainder of the division of a by b. If b is equal to zero, it will throw an error message ("SafeMath: modulo by zero"). (autogenerated documentation)
mod(uint256,uint256,string) :
This function is an internal pure function that calculates the modulo of two unsigned integers (uint256). It takes in two uint256 values (a and b) and a string (errorMessage) as parameters. It requires that b is not equal to 0, and if it is, it will throw an error with the provided errorMessage. If b is not equal to 0, it will return the modulo of a and b. (autogenerated documentation)
sqrrt(uint256) :
This function is an implementation of the Babylonian method for calculating the square root of a given number. It takes in a uint256 (unsigned integer) as an argument and returns the square root of that number as a uint256. The function works by starting with an initial guess of the square root (a/2 + 1) and then iteratively improving the guess by taking the average of the guess and the number divided by the guess. This process is repeated until the guess is close enough to the actual square root. (autogenerated documentation)
percentageAmount(uint256,uint8) :
This function calculates the amount of a given percentage of a total amount. It takes two parameters, a total amount (total_) and a percentage (percentage_). It then calculates the percentage amount (percentAmount_) by multiplying the total amount by the percentage and dividing by 1000. (autogenerated documentation)
substractPercentage(uint256,uint8) :
This function subtracts a given percentage from a given total. It works by first multiplying the total by the percentage to subtract, then dividing that result by 1000, and finally subtracting the result from the total. The result is returned as a uint256. (autogenerated documentation)
percentageOfTotal(uint256,uint256) :
This function calculates the percentage of a given part out of a total. It does this by taking two uint256 parameters, part_ and total_, and multiplying part_ by 100 before dividing it by total_. The result is then returned as a uint256 value, percent_. (autogenerated documentation)
average(uint256,uint256) :
This function calculates the average of two uint256 values (unsigned integers of 256 bits). It does this by first dividing each value by 2 and then adding the results together. Finally, it adds the remainder of each division (the modulo) divided by 2 to the result. This ensures that the average is calculated accurately, even if the two values are not evenly divisible. (autogenerated documentation)
quadraticPricing(uint256,uint256) :
This function calculates a payment amount based on a given multiplier and payment amount. It works by taking the given payment amount and multiplying it by the given multiplier, then taking the square root of the result to calculate the payment amount. (autogenerated documentation)
bondingCurve(uint256,uint256) :
This function calculates the bonding curve of a given supply and multiplier. The bonding curve is a mathematical equation that describes the relationship between the supply of a token and its price. The function takes two parameters, supply_ and multiplier_, and returns the result of multiplying the two parameters together. This result represents the total amount of tokens that can be purchased at the given supply and multiplier. (autogenerated documentation)
_msgSender() :
This function is an internal view function that returns the address of the sender of the current message. It works by using the built-in msg.sender variable, which stores the address of the sender of the current message. (autogenerated documentation)
_msgData() :
This function is an internal view function that returns the calldata of the current message. It does not modify the state of the contract and does not require any gas to be executed. The function is used to access the data of the current message, which can be used to determine the parameters of the function that was called. (autogenerated documentation)
owner() :
This function returns the address of the owner of the contract. It works by returning the value stored in the _owner variable, which is set when the contract is deployed. (autogenerated documentation)
renounceOwnership() :
This function allows the owner of a contract to renounce their ownership of the contract. It emits an OwnershipTransferred event, which notifies any listeners that the ownership of the contract has been transferred from the current owner to address 0 (which is the address of a null account). The function then sets the _owner variable to address 0, indicating that the contract no longer has an owner. (autogenerated documentation)
transferOwnership(address) :
This function allows the owner of a contract to transfer ownership of the contract to a new owner. It requires that the new owner is not the zero address, and emits an OwnershipTransferred event with the old owner and new owner as parameters. The _owner variable is then updated to the new owner. (autogenerated documentation)
setExchangeRatio(uint256) :
This function allows the owner of the contract to set the exchange ratio for the token. The exchange ratio is the amount of tokens that can be exchanged for a certain amount of Ether. The function takes in a uint256 parameter, which is the new exchange ratio, and sets the exchangeRatio variable to the new value. (autogenerated documentation)
setTokenAAddress(address) :
This function allows the owner of the contract to set the address of a token A. It takes in an address as an argument and checks that it is not the address 0. If the address is valid, it sets the tokenAAddress variable to the address provided. (autogenerated documentation)
setTokenBAddress(address) :
This function allows the owner of the contract to set the address of a token B. It takes in an address as an argument and checks to make sure that the address is not equal to 0. If the address is valid, it sets the tokenBAddress variable to the address provided. (autogenerated documentation)
Buy(uint256) :
This function allows a user to exchange tokens of one type (tokenA) for tokens of another type (tokenB). The user must provide an amount of tokenA to the contract, and the contract will transfer an amount of tokenB to the user based on the exchangeRatio. The contract will also transfer the amount of tokenA provided by the user to the user's address. (autogenerated documentation)
withdrawTokenA() :
This function allows the owner of the contract to withdraw all of the tokens of a specific token (tokenA) from the contract. It does this by calling the transfer function of the tokenA contract, passing in the owner of the contract as the recipient and the balance of the contract as the amount to be transferred. (autogenerated documentation)
withdrawTokenB() :
This function allows the owner of the contract to withdraw all of the tokens of a specific type (in this case, Token B) from the contract. It does this by calling the transfer function of the token contract, passing in the address of the contract owner as the recipient and the balance of the contract as the amount to be transferred. (autogenerated documentation)
withdrawAll() :
This function allows the owner of the contract to withdraw all of the tokens held by the contract. It does this by first creating two IERC20 contracts, one for each token, and then transferring the balance of each token from the contract to the owner. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i t1nyTi-token-sale
copy icon

Recent Use

🍞 0x760D saved
🥐 0x9cb3 downloaded
🥖 0xE5a8 downloaded

Last Publish

10/17/2022

Version

1.0.0

Creator

t1nyTi

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.