2# Deploy Smart Contract Token CRC20 & TokenSwap
After the compilation process is complete and a green check appears (meaning there are no errors), then the next step is to deploy the crc20 token smart contract and token swap to the coinex smart chain blockchain,
- Environtment = Injected Provider – Metamask
- Account = Select the account you will use
- Contract = Choose Swapper
- Click Deploy and Confirm in the wallet metamask
Wait 3-5 seconds for the creation of the crc20 smart contract and the tokenswap will be completed immediately. After the process is complete, we will get 4 smart contracts
- Smart contract TokenSwap
- Smart contract crc20 Token A
- Smart contract crc20 Token B
- Smart contract crc20 Token C
3# Verification Smart Contract
After the smart contract deployment process is complete, you need to verify the smart contract to the coinex smart chain explorer. You can upload solidity files to explorer or use single file (flattener). In this article I will use the flattener remix idea, to combine all the smart contract files into a single file.
- Install the flattener plugin in the csc ide remix, click “Activate” the plugin
- Click the flattener menu and create a flat swapper file by clicking the “Flatten Swapper.sol” button & clicking “Save”
- After flat is complete, a new file will appear, named flat_swapper.sol , copy all the contents of the file and upload it to the coinex smart chain explorer.
- Go to the smart coinex explorer & open the tokenswap smart contract
- Click “Contract Info” and click “Verify and Publish”
- Enter all required information, such as contract name, compiler, file type, license, etc
- Paste the previously copied smart contract in flat swapper.sol
- Click submit
- After completion, all the smart contract information will appear in the explorer, and then anyone can interact the contract through the smart chain coinex explorer
4# Approve Address
After the tokenswap and crc20 smart contract verification is complete, the next step is to approve the tokenswap smart contract address in the crc20 smart contract (3 crc20 smart contracts)
- Enter the coinex explorer, and enter the smart contract Token A, Token B and Token C
- Connect your wallet, click “write contract”
- Select Approve address, and enter Address smart contract tokenswap + number of tokens approve (for example I input 100000)
- Click “write” and confirm in the metamask wallet
- Do the same for Token B and Token C
- Next is to approve your wallet address, which will do the swap, the steps are the same as above, only in the address section, you enter your wallet address
5# Contract TokenSwap Information
You can see smart contract information in the contract info section, in the “Read Contract” section there is some information
- TokenA = Contains information on smart contract address token A
- TokenB = Contains smart contract address information for token B
- TokenC = Contains information on smart contract address token C
In the “Write Contract” menu is a function that you can use to interact with the smart contract
- SwapAforC = Is the Swap function from token A to token C
- SwapBforC = Is the Swap function from token B to token C
- UnswapCforA = Is the Swap function from token C to token A
- UnswapCforB = Is the Swap function from token C to token B
6# TokenSwap Test
We will test the swap function in the smart contract, make sure you have approved the address as above, because this token uses decimal 18, then you need to add the number 0 (amounting to 18), for example if I will swap 100 tokens A to C, then what you need to input is 100000000000000000000
- Example of swap token A to token C
- Example of swap token B to token C
- Example of swap token C to token A
- Example of swap token C to token B
The tokenswap smart contract creation process is very easy and cheap, you can modify the smart contract according to your wishes. By using the coinex smart chain blockchain, the process is very fast, the average transaction is completed within 3 seconds, and of course very cheap, the cost per transaction is not more than $0.005 . GOOD LUCK