How to send to multiple addresses in one ethereum tx? - ethereum

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.

Related

Finding relevant smart contract information in Blockchain data

First of all apologies for probably poorly named question but the fact that I can't formulate it better is probably partially a reason why I've not been successful in finding the answer. I am trying to understand where in blockchain data can I find specific value of smart contract method. For instance, as in the screen below, this specific smart contract 0xF59D66c1d593Fb10e2f8c2a6fD2C958792434B9c holds information about the totalAssets and pricePerShare. I can see the values in the Etherscan but now, having access to logs/events and transactions from Ethereum blockchain- can I find these values in either logs/events/transactions? And how would I go about finding that value per block in the past? Any hints how to approach it would be very helpful
To get historical data, you can refer to the smart contract view function indicating the block number at the time of which you want to view the result. For example, for JSON RPC, such a request looks like:
{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to":"contract", "data":"function signature and parameters"}, "block number"], "id":1}") ;

Updating a live smart contract

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.

Can we get transaction information recorded in the past block using Solidity in the Smart contract?

I am studying blockchain with Ethereum, and I want to use past transaction data in the Smart contract using Solidity.
If I use Web3.js module in the program written in javascript, I can get these data easily.
But I can't get these data in the Smart contract using Solidity.
Reference of Solidity says that we can get current block number, blockhash, etc., by using "block.number" and "block.blockhash(uint blockNumber)" functions, but doesn't mention getting transaction data.
(http://solidity.readthedocs.io/en/latest/units-and-global-variables.html#special-variables-and-functions)
please help me.
The answer is simple. Unfortunately, you simply can’t access old transaction or block data onchain from Solidity. At most, you can access hashes of last 256 blocks (see blockhash in documentation )
Alternatively, as a workaround you could consider using Oraclize. Oraclize represents way to read offchain data onchain, so you could try to read transaction data from Etherscan web API. The way Oraclize works is that :
You request to Oraclize smart contract what data you want to fetch from internet (some URL)
Oraclize offchain servers then detect your on-chain request
The look up the data you wanted (they'll make some http request to the URL you provided)
Once they get response, they will send transaction to your contract (calling specific callback method) containing data you requested
With such approach however, you are relying that:
EtherScan is up and running
Oraclize is up un running.
If you only care about transaction data related to your smart contracts, another way would be to store that transaction data onchain. Maybe we could gave you some more suggestions if you tell us more about what specific problem are you solving.

Best way to issue regular payouts to many wallets?

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.

Working with tokens in the ethereum blockchain

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.