@uniblock/launcher-presale v0.0.1-test.8
@uniblock/launcher-presale
This is a wrapper for the contract methods of Uniblock presale. Before you begin, please create a Uniblock account and get a Uniblock api key here
1. Set up
Follow this step to add @uniblock/launcher-presale to your repository:
npm i @uniblock/launcher-presale
or
yarn add @uniblock/launcher-presale
2. General Overview
The Uniblock presale contract allows users to launch a crypto token sale. As an example, before the crypto token is made available to the general public, the sale can help the public know about the crypto token the users or companies are selling and attract people's interest to invest in their crypto token or any other products. This package is created to simplify the usage of the presale contract. This makes the task of dealing with blockchain contracts easier for the developers. This means developers can call any contract methods in the same way as they call apis from their backend, thus allowing their applications to obtain the functionality of presale contract they deployed. For more details about this package, take a look at the documentation
3. Quick Start
This guide will introduce the flow of using the presale contract.
Step 1: Create the sdk instance
First of all, we need to create an instance of the presale sdk. After we deploy the presale contract through the Uniblock launcher, we just collect its contract address and chain ID and pass them into the initialize function with the Uniblock api key:
const uniblockApiKey = <YOUR_UNIBLOCK_API_KEY>
const contractAddress = <YOUR_CONTRACT_ADDRESS>
const chainId = <YOUR_CHAIN_ID>
const presaleSdk = initializePresale(uniblockApiKey, {contractAddress, chainId})
Note:
You can create your presale contract through the uniblock dashboard and get the contract address here
Step 2: Check token Address
To check the token address of the token that is on sale in this presale, we simply call the method of getTokenAddress on the sdk instance:
const presaleToken = await presaleSdk.getTokenAddress()
Step 3: Select a method to purchase presale token
We first list out all supported payment methods:
const paymentTokens = await presaleSdk.getPaymentMethods()
The above method will give a list of erc20 tokens that can be used to exchange for the presale token. We can select any of the tokens and pass them into the getPaymentMethodRate to obtain the exchange rate:
//option 1:
const rate = await presaleSdk.getPaymentMethodRate(paymentTokens[0])
// example: { presaleToken: 1, paymentToken: 1}
Then you need to allow your presale contract to spend your payment tokens. You can do this by going to the etherscan to call the increaseAllowance
by providing the spender address with this presale contract address if your presale contract is verified or run the following code:
const allowance = 100 // set allowance to be 100 for example
await presaleSdk.increaseAllowance(<ERC20_TOKEN_ADDRESS>, BigNumber.from(allowance), signer)
Step 4: Buy the presale token from the contract
To purchase the token, we will first need to check if our current time is within the start time and end time of the presale. To obtain the start time and end time of the presale, simply call these two methods on the sdk instance:
const startTime = await presaleSdk.getStartTime()
const endTime = await presaleSdk.getEndTime()
Then in order to call the buy method, we first need to create a Signer instance.
The creation of the Signer instance will differ depending on the platform of the application:
browser environment (we are using metamask in this example)
const ethereum = (window as any).ethereum; const accounts = await ethereum.request({ method: "eth_requestAccounts", }); const provider = new ethers.providers.Web3Provider(ethereum) const signer = provider.getSigner(accounts[0]);
nodejs environment:
const provider = new ethers.providers.JsonRpcProvider("RPC_URL", 5); const signer = new ethers.Wallet("WALLET_PRIVATE_KEY", provider);
After we create our signer instance, we can then provide our selected payment method, the desired amount and signer to the buy method:
await presaleSdk.buy(paymentTokens[0], 20, signer)
Step 5: Withdraw the presale token after the presale
After the presale is over, the user can withdraw the presale token by calling the withdraw/withdrawAll method. Before they withdraw, they need to check if the current time is after the withdraw time of the contract. To check withdraw time, simply call the getWithdrawTime method:
const withdrawTime = await presaleSdk.getWithdrawTime()
Create a Signer instance similar to how it was done in step 4 and call the withdraw method:
await presaleSdk.withdraw(20, signer)
await presaleSdk.withdrawAll(signer)
Note:
In case if the claim time is passed but the presale endtime is not reached, users could choose to call buyAndWithdraw method as the following:
await presaleSdk.buyAndWithdraw(paymentTokens[0], 20, signer)
9 months ago
8 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
12 months ago
12 months ago
11 months ago
12 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago