2

I'm still a newbie with ethereum and I want to know if it is possible to customize the structure of a transaction in order to add extra fields like a message or an integer or anything else.

If the answer is yes, can you please give me some good hints to guide my researchs.

Thank you!

3

In Ethereum, payments are normal functions with value attached. That means anything you can pass to a function you can include in a payment. It's fairly common to have some data about what was bought together with the funds to pay for it.

Simple example:

function checkOut(bytes32 itemId, uint qty) payable returns(bool success) {
   // do stuff like check the math
   if(items[itemId].price * qty != msg.value) throw;
   // track inventory, status, etc.
   return true;
}

Example assumes a struct full of item information and checks the price * qty matches the ETH sent with the transaction (msg.value). Throw reverts state changes and gives the money back in case that check failed (error or mischief on the front-end).

This example has a payable function: http://solidity.readthedocs.io/en/develop/solidity-by-example.html#safe-remote-purchase

payable is used to explicitly declare that receiving ETH is allowed, otherwise they autotmatically reject unexpected funds for security reasons. It's a relatively new feature for non-payable functions to throw when they receive funds.

Hope it helps.

| improve this answer | |
  • Thanks for this answer!! Since my goal is to customize the transactions' structure, what would you recommend me doing in the first place? Reading the solidity's documentation? – Everblack Feb 9 '17 at 11:11
  • Where to start is a fairly loaded question. It's a strange universe and there is necessarily a bunch of stuff around the transaction that you'll need to pick up. I got the most joy early on by playing with simple examples in Browser Solidity. Suggest you keep it really simple until you get a feel for how the compiler tool works, how to interact with the contract and generally what's going on. The "Greeter" example, for instance. Don't worry about making anything useful for a while. – Rob Hitchens Feb 9 '17 at 11:37

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.