Help! Buy and mint tokens for my bachelor thesis

Hi guys!!

I am working on the concept of a DApp for my bachelor thesis. The general idea of the app is to connect Cocoa bean farmers and buyers and enable them to have trustless transactions, where counterparty risk is decreased. Basically, the farmer delivers his cocoa to a location and there weight and quality of delivered cocoa is measured. This sensory data (IOT) is fed to a smart contract (SC) which mints Cocoa token (CT) depending on delivered quantity of cocoa. The smart contract is coded to mint 1 CT per kilo delivered. For example, through the frontend app the farmer agrees to sell 5kg of his cocoa for 10 dollars/kg to the buyer. Thus, once delivered, the SC will mint 5 CT and automatically transfer them to the farmer’s wallet, now the buyer needs to buy the CT for 10dollars/CT = 50 dollars. Another Smart Contract would now automatically check whether funds of buyer were sufficient, then buy the tokens back, transfer them to the buyers wallet and transfer the money to the farmer.

The idea would be to create digital assets at the time of delivery. These digital assets, CT in this case, would guarantee asset rights, and track location of asset at any specific time during the transaction. Now I’m still not clear on how this would be completely realizable.
But so far what I’ve done is learn how to mint an ESC20-Token and send it from one account to another with truffle console/metamask! I’ve also learned how to write a buy contract with functions that enable to buy tokens from contract 1 with Ether. Now my questions are:

  1. I know that I can test contract 2 (buying tokens) with truffle console, however, is there a way to buy tokens and test buying functions with a UI that connects to my local ganache client, like MetaMask?? Because MetaMask only allows me to send Tokens from one contract to another, but how do I invoke the buy functions? e.g the function
function buyTokens(uint256 _numberOfTokens) public payable {
require(msg.value == multiply(_numberOfTokens, tokenPrice));
require(tokenContract.balanceOf(this) >= _numberOfTokens);
require(tokenContract.transfer(msg.sender, _numberOfTokens));
  1. How would I go on about buying these tokens with FIAT money? In the contract, I specified the amount of wei that each token costs. Can you specify other currencies as token price? If I deploy the contracts to a testnetwork / the Ethereum public, well the buyer could buy the tokens with ETH, but how can the buyer actually buy the tokens for a predetermined price? (e.g in this case 50 dollars for 5 CT). How can one remove volatility from the equation? Because, if let’s say farmer and buyer agreed on the 17.05.2020 that payment in the near future (as soon as cocoa is delivered and token minted and bought (lets say this happens a month later, on the 16.06.2020) would be 50 USD, the buyer would need to buy 50 USD of Ether at that day and the ether, once transfered to the farmers wallet, would need to immediately be sold again for the same dollar value, so as to not suffer any volatility risks.
    My idea: Mint a second token and have it be equal 1:1 to the USD. Buy CT with the second token.
    This way, the only currency volatility risk would constitute that of the dollar.
    But here again… how would you do this in practice?? The buyer would need to buy the second token e.g with his bank account, then buy the CT from the farmers wallet… But how do you ‘‘sell’’ a self-minted token directly for USD in practice??

Thanks if any guys of you have an input for how to solve these problems! I need to hand in my thesis before Tuesday LOL. Gotta hurry and solve these problems. The aim is to be able to conceptualize the app, I don’t need to develop it fully! Just knowing how to mint the tokens and buy and exchange them in practice would be enough.

Best regards,
tschilpi

1 Like

Hi @tschilpi,

Good luck with your thesis.

You would need a dapp which calls functions on your smart contract.

The quickest way to do this is:

  • OneClickDapp - https://oneclickdapp.com/ generate a dapp from your smart contract (I haven't tried for a local testnet) and then you can read/write
  • UDAPP - bare bones universal dapp (I used to use pre-OneClickDapp) https://kumavis.github.io/udapp
  • Etherscan - verify your contract on a public testnet and you can read/write to your contract using injected web3 (MetaMask)

The next step after that is to build your own dapp to do this.

Instead of selling tokens for Ether you could sell for a specific stable coin (such as DAI) which are designed to be non-volatile and track the value of a fiat currency.

You may not need a token at all, if the buyer could put the payment into an escrow contract. (e.g. https://solidity.readthedocs.io/en/v0.6.8/solidity-by-example.html?highlight=escrow#safe-remote-purchase). Though I don't know how realistic this is for the buyer to pay upfront rather than have some sort of credit terms.

Buyers/sellers would need to use exchanges to convert from fiat to a crypto currency (Ether or a stable coin) and then could pay using the crypto currency.

Another issue is that the transactions would be public, so each buyer and seller could see the transactions. Whilst they would be pseudo-anonymous, as soon as anyone attached an identity to an address, transactions could be identified.

Projects like https://docs.baseline-protocol.org/ are looking at how to have confidential transaction on the public blockchain.