6

Ok, I've seen this at the DAO (Distributed Autonomous Organization) sample tutorial here. And I also looked it up at some other places like the official Solidity documentation here for instance. But I still can't understand what is going on at that line.

I know p is a proposal struct, from which the recipient is a member of type address. So I guess it just boils down to 'call' and 'value' attributes or method, whatever they are.

I read 'call' is a method, but here it is being referenced as if it were an attribute. And what's that funny thing about using two sets of parentheses over there? is the first function returning another function that we are executing?

Best regards

Nelson R. Pérez

3

Interesting question, and I don't have a complete answer. But from the Solidity docs under address it says:

call, callcode and delegatecall: Furthermore, to interface with contracts that do not adhere to the ABI, the function call is provided which takes an arbitrary number of arguments of any type.

Example:

address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName");

My interpretation is:

p.recipient.call.value(p.amount * 1 ether)(transactionBytecode);

is calling the address (p.recipient) setting the given amount of the transaction value to (p.amount * 1 ether) and setting the data field of the transaction to (transactionByteCode)

This would be similar to sending a normal transaction with the web3 api. pseudo-code:

tx = {
  from: (in the example, the calling contracts address)
  to: (p.recipient is the address),
  value: (p.amount * 1 ether),
  data: (transactionByteCode),
  ...
}
web3.eth.sendTransaction(tx)

More Info: After experimenting and digging around a bit I found this:

Many apps, like the multisig wallet and the democracy DAO, allows the users to ask the contract to execute a custom solidity call to another contract. This is a very powerful feature that allows, for example the user to have a second authentication for any transaction in the wallet contract; or allows the DAO to own and maintain names in the registrar, or the DAO to own custom coins.

This is usually done with the solidity .call feature that will have this parameters:

someAddress.call.value(_amount)(_data);

Where someAddress is an address to another contract, _amount is amount of ether in wei and _data is a custom abi encode of function that the user wants to call.

So my original answer is a bit off. But, if you do in fact make the call and _data is NOT an abi function to execute, _data will be pass to the data field in the transaction, but it appears the value will not.

| improve this answer | |
  • Yeah.. that's basically all the docuentation I could also find about it, but it doesn't do much to clarify things to me. For once, if "call" is a function as stated there, how come you can access "value" like if it was some attribute of it? are all functions in solidity like that? and what about that double ()() thing over there? – Bilthon May 25 '16 at 15:00
  • this is all correct, just note that .call should always raise eyebrows as it sends all gas along to the destination address which might very well be a contract. It the target is a contract then that contract can be designed to recursively call the initial function again. This is called re-entrancy and if the contract is not designed carefully it can lead to lots of fun and popcorn: hackingdistributed.com/2016/06/18/analysis-of-the-dao-exploit – SCBuergel.eth May 8 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.