Multiple ERC20 tokens in a DeFi platform - ethereum

I'm building a DeFi application on Ethereum, and I would like to implement the Deposit function. Everything works fine between ETH and a ERC20 token that I built, but I would like to add some tokens like aToken for AAVE or cTokens for Compound that the user will receive after a Deposit call.
So the question is: is it possible to add a function in my smart contract to create multiple tokens without creating a smart contract for each of them? If not, I have to create a different contract for each token I want to add in my app or there is a best method to do it?

Yes this is possible. You can transfer the tokens to the user's address after the Compound Protocol mint operation. This can be made generic using the ERC-20 transfer interface. Be sure to account the amounts users are due and beware of the reentrancy vulnerability.

Related

Sign raw transactions in Logic Apps

I'm new to Logic Apps. What I would like to achieve is to sign and send raw transactions to Ethereum network using Logic Apps service. Currently, what I have done is to transfer ERC20 tokens from the token contract itself in Logic Apps.
What I would like to achieve is to transfer tokens from account to account which is the transfer from the method the ERC20 protocol.
How can I do that in Logic Apps? In my opinion, it's required the sender to sign the raw transaction message.
While I am not familiar with ERC20, since you seem to be using web3py, I believe you can offload the signing to an Python Azure Function which you can invoke from within a Logic App.
As for signing a transaction, looks like this is covered in the web3py docs.

How can ethereum token use as payment gateway on ecommerce website

Everyone can create ethereum token by solidity codes but don't know how can this token integrate as payment gateway in ecommerce website.
For real project . This token need frontend web wallet /android wallet and integration to every website as payment.
Plz suggest me .how can find this way.
What need more to study.
Token is not a payment gateway. If i understand your question correctly, you are asking, how can you interact with a token that you have created through Solidity from frontend. One use case would be how people can use the token that you have created to purchase some item. For this the users should already be holding the tokens. This can be bought from an ICO or from an exchange. Basically there's a couple of functions in ERC20 token i.e., approve() and transfer() that will approve apps like exchanges to perform transactions on behalf of the owner of the token. Once the users have those tokens they can purchase items from it. Again, you have to write the logic how and what you expect users to do.
ERC20 Token is works likes Currency.And solidity is a programming language. which we used for write the smart contract. if you want to invoke your function then you need to create wallet account ,after that you can do transaction using with web3js. you can get ether for testing purpose from faucet.Basically these are functions in ERC20 token i.e., approve() and transfer() that will perform transactions
I don't suggest using ERC20 tokens as payment method.
Ethereum network is not fast enough,you need 30 confirmations to make sure you received the token, some times the delay can be 1 day
Cost is high, when you transfer token ,usually you have a smart contract, it costs lots of gas
Ether price is not stable, it drops 90% of value from Jan 2018 to Dec 2018. it will be hard for estore to maintain profit.
However if you still want to do that, yes, you can create your own gateway using tokens as your accepted currency.

Can a smart contract automatically send message to an user address in ethereum blockchain

I'm a new beginner in the ethereum Blockchain.
I want to implement a smart contract that verifies the authenticity of a user and then send a message to a cloud service (with is the smart contract creator) in case of positive verification to grant access to the user.
My question is it possible for a smart contract to return results of his methods invocation to another blockchain user and how we can do it?
A smart contract cannot make calls outside of the blockchain. i.e., you cannot have it call an http endpoint or something similar.
In ethereum, the usual way of achieving something like this is:
Have the user make a transaction passing relevant data to your smart contract
The smart contract runs whatever verification logic it must on that data
The smart contract logs an Event
You have an ethereum node that your code connects to and listens for these events.

Upgrading smart contract in ethereum

I am trying to write upgradable smart contract in ethereum. Can anyone give an example of upgradable smart contract in ethereum and accessing data.
To write an upgradable smart contract I suggest you do the following (works for me):
Create a storage contract on which you will store all your map and variables. Add a modifier to the functions changing state. This modifier should require that an address must be present in a specific map (let’s call it authorized) to change the state of map or variable. Place the owner’s address in that map.
Write a function to authorize external address on the storage contract
Deploy another contract containing the logic of your app.
Autorise the logic contract on the storage contract.
Upon upgrade of the logic, deny access to the storage contract from the logic contract, deploy your upgraded logic and link the new contract to the storage.
Tadaa you now have an upgradable set of smart contracts.
Smart Contract cannot be replaced, but you can create a smart contract proxy to be able to replace the calling of all new Smart Contract functions (previous smart contracts cannot be removed on the main network ethereum).
Complete explanation and examples can be seen Here
You can implement follow Proxy Pattern
Blog
https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357
Smart contract upgradability is a state of the art area. Currently, there are a few solutions, but each of them has its own pros and cons. Here are the solutions with examples:
https://consensys.github.io/smart-contract-best-practices/software_engineering/

ERC20 token , transferfrom crashes , what would be the consequences?

We have created an ERC20 token for TGE/ICO .
In our testing we have found that transferFrom function does not work and crashes
rest all the functions are working properly . the tokens are already deployed on mainnet
what impact will this have apart from user not able to transfer on someone's behalf ?
Also will this impact later when the token comes on exchange in anyway ? or user is only going to use transfer function?
What do you mean by "crashes"? Are transactions rolled back and the resulting state correct or are tokens lost/irretrievable as a result of using the function?
Either way, as a user I would not want to purchase your token. If one of the ERC20 functions doesn't work properly, I certainly wouldn't have trust that the contract is secure. The impact will be that you will have irate customers who won't want your token. Users will expect to be able to use the transferFrom function since you're advertising your token as an ERC20 compliant token. I'd also think that no exchange will accept your token.