Hello guys .
How a smart contract A can buy erc20 token from other contract B. stores the erc20 token data in contract A.
In short,
Can one contract own tokens of another contract?
Is there any tutorial?for making this possible?
Oct 3, 2020, 2:13 PM
Not sure exactly what you need but you can trade using uniswap api or search "mastering ethereum" pdf there is a section that explain how contract can transfer token.
Or maybe openzepelin crowdfunding library it depends what you need.
Oct 3, 2020, 2:28 PM
buy then transfer?
no need for exchanges
Oct 3, 2020, 2:31 PM
No no .
I want to develop a smart contract where a smart contract can buy multiple erc20 for a user.
User(msg sender) ---> calls function of contract A function named buy(erc20 address,uint amount);
After calling the buy function.
Contract A will buy some amount of tokens for a user and it will store the token data into the contract A.
I want to develop a smart contract where a smart contract can buy multiple erc20 for a user.
User(msg sender) ---> calls function of contract A function named buy(erc20 address,uint amount);
After calling the buy function.
Contract A will buy some amount of tokens for a user and it will store the token data into the contract A.
So that instead of storing erc20 data into the user wallet.
The token data will be stored into the contract itself
The token data will be stored into the contract itself
Or in another words.
A smart contract that can act as a wallet for storing multiple erc20 tokens for a user.
A smart contract that can act as a wallet for storing multiple erc20 tokens for a user.
Oct 3, 2020, 2:42 PM
Pretty sure that's what argent wallet is doing.
The code is on github
Oct 3, 2020, 2:48 PM
Search for smart contract wallets, Argent is one of them
For the buying stuff you can use Kyber or Uniswap onchain
Oct 3, 2020, 2:54 PM
Lol,
Actually ,i had the idea for making this project.but someone is already working on the project.
Actually ,i had the idea for making this project.but someone is already working on the project.
One more thing how a erc20 token price is determined.
Lets suppose i want to develop a token where each token price is equivalent to silver/gold.
So what would be the logic on the smart contract to tokenize real world assets.?
Lets suppose i want to develop a token where each token price is equivalent to silver/gold.
So what would be the logic on the smart contract to tokenize real world assets.?
Oct 3, 2020, 4:50 PM
Typically tokenizing real world assets means that the token represents the asset - not that it has the same value.
But if you want to peg a token to a real world asset's value it gets rather complicated as to Ken's value is based on supply and demand
But if you want to peg a token to a real world asset's value it gets rather complicated as to Ken's value is based on supply and demand
Oct 3, 2020, 5:06 PM
Yeah exactly. I am just curious about how these crypto info sites like coingecko/coinmarketcap tracks a price of erc20 token.
Like suppose my idea is to create a erc20 token whose price is pegged to price of silver/gold or whatever.
So,
For fetching price of gold/silver i will use oracle.
But my second question is how to set price of the token in the smart contract?
Like suppose my idea is to create a erc20 token whose price is pegged to price of silver/gold or whatever.
So,
For fetching price of gold/silver i will use oracle.
But my second question is how to set price of the token in the smart contract?
Oct 3, 2020, 5:22 PM
The price can be retrieved from either centralized exchanges (if the token is there) or decentralized ones.
And for how to keep the price of your stable token stable... Well, that is an interesting discussion. To put it simply: there is no trivial way to do it. The easiest way I can think of is to reduce / increase balance of all token holders according to the underlying price. But the tricky part here is how often to do this rebalance as it costs gas
And for how to keep the price of your stable token stable... Well, that is an interesting discussion. To put it simply: there is no trivial way to do it. The easiest way I can think of is to reduce / increase balance of all token holders according to the underlying price. But the tricky part here is how often to do this rebalance as it costs gas
Oct 3, 2020, 5:27 PM
Any other expert wants to join this discussion? Please give your thoughts on this
Lets say i made a token called silverCoin.
I developed a token sale contract. Using oracle i will fetch current price of silver and i will store the price in a variable in ether. in order to buy a token a user must call buy function with parameters (amount) .i will set a require condition there
Like require (msg.value == currentPriceofsilver).
If this condition mets then one can buy the token.
Is this approach correct?
I developed a token sale contract. Using oracle i will fetch current price of silver and i will store the price in a variable in ether. in order to buy a token a user must call buy function with parameters (amount) .i will set a require condition there
Like require (msg.value == currentPriceofsilver).
If this condition mets then one can buy the token.
Is this approach correct?
Oct 3, 2020, 5:35 PM
Could do msg.value >= priceOfSilver and return any excess over priceOfSilver to msg.sender
If you also wanted to restrict only to buying whole units
Oct 3, 2020, 5:54 PM
Well practically, the price is controlled by holders. Suppose you are crowdsaleing token at 100$ a piece. If customer A buys it and sells it for 80$ in some exchange, that's the current price of the token right?
Or yeah, rebase like AMPL. But the coin won't stay stable...
Oct 3, 2020, 7:06 PM
In theory it might? What will go wrong?
Oct 3, 2020, 7:30 PM
Well... Lets just say people started to hate silver :)
Price dumps, token rebases like hell and people gets angry. Tries to sell off at whatever price, price further drops...
And hence, unstable💁🏻♂️
Oct 3, 2020, 7:34 PM
You could say the same about any stablecoin/token. They all require some amount of trust I believe
Oct 3, 2020, 7:57 PM
Theory vs practical🙃
Damn these oracles cost a lot...
5 cents for generating a single random number. Is it me being cheap or what do you guys think?
Oct 3, 2020, 8:10 PM
Yeah i think you are right.
Anyone here who developed stable coin.
Please share your thoughts or
Share your solidity piece of code(if public) .
Please share your thoughts or
Share your solidity piece of code(if public) .
Oct 3, 2020, 8:40 PM
You should check how Synthetix is doing it. If you search cap finance git they also released code for synthetic asset that follow real world stocks, gold, etc. Basically they all use an oracle. You also have wrapped asset like wbtc or renbtc that are backed by btc or SBTC which are synthetic.
Oct 4, 2020, 3:12 AM