Smart contract; A solution for high card fees

Adamsmajs
Learn Bitcoin & blockchain
7 min readJun 9, 2024

Introduction:

At first, we got an idea to create our own crypto token, which was meant to be used by students of our University primarily, and in case of success then spread wider. One day, we got a message from mister Jedlinský, telling us that his other students from another school has problem, which could be solved by using cryptocurrencies. He then left us contact on them. After a period of time, we arranged an online meeting, where we were given details about their problem. Long story short, those students were selling coffee to their classmates, and suffered losses from inappropriately high fees from card payments (they used a website called Wix, connected with payment gate Stripe). Their customers ordered the coffee on the Wix and paid in forward with card with the help of Stripe payment gate. The students were searching for another way how to bypass those fees, but the fees were similarly high from other providers, too. We caught the opportunity and offered those students our help. They told us that they need to have this problem solved by the start of the next school year, since it is part of their high school thesis. The web is right now cancelled, and under development. We shared our idea, and the students were glad that they found a cheaper alternative and told us that they plan to work on a video/text guide on how to use crypto and they even plan to provide some discount for students that would use the coffee token as a payment method, to incentivize the students to use it. We have talked with them in detail about how this token works and provided further information that would help them make the guide. We also agreed to keep in touch during the summer vacation to provide help and information if needed.

The project:

Now let’s talk about how exactly did we approach this term project. As it was already mentioned we wanted to create a school token, so that’s what we did. We created a token called Coffee Token (CFT)(0xa395df759091fba819e37c0d53b1c785422c26f7) on the Binance smart chain. At first, we were having trouble to find a suitable blockchain that would offer low fees for token and contract deployment. But after some digging we found out that the Binance smart chain is a reliable blockchain that provides low gas fees, as well as supports tokens and contracts programmed in solidity. So once we figured out which blockchain we want to use we created our token. This process wasn’t that challenging given that we have already done similar assignment during the semester. So we created this token and deployed it on the blockchain (at first we deployed it on the testnet as well as the smartcontract). We minted 50 000 000 tokens, which in hindsight was not really necessary given the way that these tokens will be used in, but we do not find it as a problem. Now came the trickier part; How to actually use these tokens? How will they serve as a mean of exchange for these students? There are several ways to sell your tokens. Of course it would be really hard for us to list our token on some centralized exchange like Binance or Kucoin and etc. Then we thought that they could sell their tokens using some decentralized exchange like Pancakeswap or Uniswap. But again, this was not really advantageous for the students, given that they would have to provide liquidity for their token’s pool, this would mean that by selling these tokens the profits wouldn’t go directly to them, they would only get a percentage from the transaction based on the chosen liquidity provider fee. In our research, we also found out about the token provider services, but these services are not really suitable for a small scale project like ours. Finally, we decided to sell these tokens through direct sale and what is a better way to do that than with the help of another blockchain technology, smartcontracts. Once we have settled on the smartcontracts, using some YouTube tutorials and GitHub source codes after a few unsuccessful tries able to create our very own smartcontract that would allow the students to buy the Coffee Token (CFT). We faced troubles when deciding for what crypto will the students exchange the CFT, but we settled on BNB the native cryptocurrency of the BSC. We set a fixed exchange rate of 0.0018 BNB for one CFT. But the BNB is quite volatile so the students would have to adjust this exchange rate if there were some significant movements in the BNB price. That’s why we also created a smart contract that would allow the students to purchase the CFT for a stablecoin USDT (Binance-Peg BSC-USD). This smartcontract provides fixed price of one CFT for one USDT, but the transaction fees are a bit higher when using this smartcontract in comparison with the BNB. The students in charge of this project have yet to decide which smartcontract to use or if they will use both.

When creating the USDT smartcontract, we couldn’t figure out how to set the exchange rate so that it would work properly, the problem was that we assumed that the BSC-USD had only 6 decimals but after we found out that it had 18 decimals (same as our token) we were able to set 1:1 rate. But using this contract comes with an extra step, users also have to interact with the Binance-Peg BSC-USD smartcontract (0x55d398326f99059fF775485246999027B3197955) to approve the spending function, where they will paste the address of the contract into the field Spender and then the amount of tokens that can be spend (1*¹⁰¹⁸ = 1USDT), but this 1*¹⁰¹⁸ is fairly easy to input given that the decimals can be automatically entered using the plus button.

These two options are provided to address the volatility issue of the BNB so that the sellers wouldn’t have to adjust their price of coffee expressed in CFT. On the other hand, the USDT contract is a bit harder to use given the extra step that has to be done (i.e. approving the contract as spender and setting the amount that can be bought beforehand).

Now how do these smartcontracts work? Both the BNB and the USDT smartcontract consist of three basic functions. First function is the swap “buyToken” function, that allows the students to purchase the token. The exchange rates are BNBcontract = 0.0018BNB for 1 CFT and USDTcontract = 1:1. Second and third functions are the “withdrawBNB” (or USDT) and “withdrawToken”, which allow ONLY the creator of the smartcontract to withdraw either BNB or USDT that was used in the exchange or the CFT that were send to the contract buy the creators. (By creators here we mean the address that created the contract for now we used our own wallet address because the students wanted to see how and if it will work before they create their own. We also provided them with the source code for the contracts so that they could create their own, also guided them through the process of deployment and setting the smartcontract).

The address of the BNB contract: 0xF2F0a12B4350B336F48349B31A596A790D19E5F8

The address of the USDT contract: 0xbf02b6bf75c0d4615b198c45950e2f451a146a37

The practical aspect of our contract is that it will allow the students that are leading their coffee project to decrease their costs when it comes to transaction, while also spreading knowledge about how the crypto tokens and smartcontract work and how can they be used in the real world. Of course the extent to which this will help increase their profit margin is up to the students to incentivize their fellow schoolmates to use this payment, although we cannot directly influence them, we tried to make the process of purchase of the CFT as simple as possible so that it wouldn’t discourage them from trying. The fees for purchase were at the time of testing as follows:

BNB contract = buyTokens fee was 0.08USD which is lower than 0.29USD (comparing with the flat fee 6.5Kc from the payment gate)

USDT contract = buyTokens fee was 0.15USD which is still lower than 0.29USD

We can see now that the fees have been pushed on to the students that are purchasing the tokens, but that’s why the creators of this project agreed to provide the users with some sort of discount. The fees for withdrawal that fall on to the owners of the smartcontract were for the BNB contract ranged from 0.04 to 0.08 USD and the USDT contract had 0.08USD fee for token withdrawal and 0.11USD fee for USDT withdrawal.

How to interact with the smartcontracts:

BNB contract

1. go to https://bscscan.com/ than paste the code of the BNB contract

2. once the page of the contract has loaded click on “contract” button with green checkmark

3. then go to write contract

4. connect your metamask wallet

5. click on the buyTokens button

6. put in the amount of BNB u want to spend (0.0018 BNB = 1 CFT)

7. confirm the transaction in wallet (make sure that in metamask u can see the amount of the CFT that will be send to your address, if u don’t see it refresh the page and interact with the contract again)

USDT contract

1. go to https://bscscan.com/ and paste there the BSC — USD smartcontract address 0x55d398326f99059fF775485246999027B3197955

2. once the page of the contract has loaded click on “contract” button with green checkmark

3. then go to write contract

4. connect your metamask wallet

5. click on the approve button

6. paste the USDT contract address into the “spender” field

7. put in the amount of USDT that you would like to spend in the format of 1*¹⁰¹⁸ i.e. if u want to spend 5USDT put in 5*¹⁰¹⁸, u can easily fill in the decimals by clicking on the plus button

8. go to https://bscscan.com/ than paste the code of the USDT contract

9. then the steps are the same as in the case of the BNB contract, but when you are entering the amount of USDT enter the same amount that you approved or less and also you have to put it in the format of 1*¹⁰¹⁸

Lastly the students that have purchase the CFT will simply send the CFT (based on the price that the students in charge of this project will set) to the address of the coffee sellers as a confirmation that they have in a sense already paid for their coffee.

--

--