I'm trying to create a contract that will dish out regular inflation to all holders of the token. Every x period, it needs to scan the addresses and calculate their inflation, minting new tokens and adding it to their total.
What is the most cost efficient way to do this? Is it cheapest to iterate over the map and update each address, or better to calculate all values in memory and replace the map? Perhaps there is a better way I'm not thinking of.
Not sure how big the map could get, but cost efficiency is key here.
Thanks!
The cheapest way to do this is to have a smart contract function that allows a wallet holder to "claim" their inflation payment. e.g. instead of iterating over every address, you let the wallet holders to do the inflation calculation just for their address.
The cost to you is 0, just have to ensure the smart contract logic is correct
If your intention is to regularly send token/eth to account addresses I urge you to read up on the withdrawal pattern. If you do not follow the withdrawal pattern, a malicious party can set up a smart contract that will get your transaction stuck during the payout.
Instead of sending funds directly you create a map about how much each address is allowed to withdraw. This is very similar to the map about which address holds how many token.
When transferring out of your contract now, only the transaction of the withdrawing party is affected.
Related
I am planning out a new project in which I need to connect one particular Fiat payment gateway to my smart contract. I don't want to have a system with a centralized backend, so I am exploring the possibility to use Chainlink to communicate with API and then pass response to my smart contract. I know that Chainlink allows any contract to access any external data source through their decentralized oracle network. The problem is I can't approximate how much LINK it will cost me to get a response from 1 oracle. Is there some average cost of a 1 response from an oracle and what determines such cost
I tried to look up this information, but it does not seem that this topic is discussed much. Also probably I didn't look in the right place
The problem is I can't approximate how much LINK it will cost me to
get response from 1 oracle.
Nobody can. When you make a request to oracle, you are calling a smart contract function and this will cost you gas which varies depending on the congestion in the system. if system is busy, it will cost more gas. Also when you interact with the chainlink, you are actually passing data to chainlink smart contract which makes some calculations, so you pay for those gas too.
Calling one oracle is sending a request to one oracle. oracle is a chainlink node operator, and it set its own price. But sending a request to only one node is not a decentralized approach even though each node have multiple data resources. you should make a request to several nodes meaning that you need to pay each node operator. when you make a request to several nodes, you receive the average of those responses.
The service you want to use is Chainlink Any Api, and in the service the cost of LINK depends on the node operator you are using.
There is a fee required by node operator. When you send a request, you actually require Chainlink node to provide a service. Usually the service is not free and the fee of a request is set by the node operator. The fee varies across different node operators. If you are only a consumer to use service provided by node operators, you just need to check the fee of different node operators.
you, of course, also has to pay gas fee for your transaction, but that it it costed in ETH rather than LINK (as you asking how much LINK it will cost, I assume you know it).
If you are a node operator and want to run the service for yourself, you may want to consider the following 2 factors:
Congestion of the system mentioned by #Yilmaz. When the blockchain you are using is very busy, the gas price is high so that the more gas fee, which is the result of (gas price) x(gas limit), will be cost more.
The logic of fulfill function in your contract. Fulfillment function is the "callback" function of Chainlink Any Api. Oracle node will fetch the data demand in the request and then call the fulfill function in consumer contract. In fulfill function, logics varies from simply saving the data in a variable or doing some calculations. The more complex logics, the more gas limit required.
Hope it helps!
Is there a way to verify that it is possible to sell a token?
There are a lot of honeypots, so you can buy a token, but then you will be not able to sell it.
I have found that there is a possibility to estimate gas for the swap transaction e.g. on the Uniswap, but in this solution, there are some conditions. The token has to be approved and you have to own some number of the token, so it could be expensive. Do you know any other method to verify that? For example, interacting with the token contract?
Example contract: https://etherscan.io/address/0x419d0d8bdd9af5e606ae2232ed285aff190e711b#readContract
There are also tokens with 100% sell fee, but it is not easy to define the contract internal fee (there is not one method to do that).
If I have a smart contract that has the addresses of some other smart contracts hardcoded inside it. E.g. maybe my contract has the addresses of some external yield farming vaults that it periodically deposits some balances to.
Now lets say that I want to update that list of addresses and remigrate it without upsetting the operation of the current contract.. what is the best way to do it ?
Ethereum bytecode is immutable, so the simple answer is: You can't update the hardcoded addresses. You'll have to create a new contract and this time save the addresses into variables that you can update later.
How can I make bitcoin like transaction in ethereum (web3js particular), when I need to send to multiple addresses defferent amount in one transaction to save fee?
From Péter Szilágyi's answer on Ethereum StackExchange, it seems that it is a bit indirect as compared to Bitcoin. One transaction can only have one output, but you can create a smart contract that will be able to send to multiple outputs.
I am writing a test application that allows people to purchase tokens.
I am adapting the example from here: https://ethereum.org/token#the-code
Here are my questions:
What is the best way to have a registry of purchases? I would assume this can be a simple web interface that queries the block chain to see who has bought what.
If this is correct, does this mean running geth on a server in order to have the latest blockchain available and then using some kind of PHP / Javascript library in order to query the blockchain every so often?
What is the best way to sell tokens? Could this be done via a web interface or would it be best to sell via the ethereum wallet? Or both?
Lets say I want to split a token into a number of parts as such:
A: A full token = 1
B: 1/10th of a full token called a 10token
C: 1/10th of a 10token called a 100token
D: 1/10th of a 100token called a 1000token
What is the best way to represent this?
For instance, if someone owns a full token they have 100% of that tokens rights. However it would be possible for many parts of a token to be owned by different people who will share rights according to their share.
Visually, it would look something like this:
How to do this is a puzzle to me.
What is the best way to have a registry of purchases? I would assume this can be a simple web interface that queries the block chain to see who has bought what.
You can do the registry in your token sale smart-contract by making event like this
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
In this case you will be able to watch event log later and get all the addresses you need.
Another approach is to add a simple map to your contract like this mapping (address => uint256) public deposited; and add elements to this map on purchases.
About the representation of the registry for the users you better just take a look at ICO's you like and make it in the same way.
What is the best way to sell tokens? Could this be done via a web interface or would it be best to sell via the ethereum wallet? Or both?
I would say both. But it depends on who are your tokens for. If you sell only using ethereum wallet you will loose a lot of users not familiar with blockchain.
Lets say I want to split a token into a number of parts as such
Take a look at the solutions offered by OpenZeppelin project. Just read their contracts code and I think you'll find solutions you were looking for in this post.