56

Summary Your original contract code would not work correctly until I added a constant to the function definition to indicate that this function does not modify the blockchain. I had to use the method signature of double(int256) instead of double(int) to get the eth_call JSON-RPC to work. The Details Run Your geth Instance You can use the Testnet ...


31

An Ethereum transaction - as in, what you pass to sendRawTransaction() - consists of the following fields, in order and RLP-encoded (note that the field names are not part of the encoded data): nonce - transaction sequence number fr the sending account gasprice - price you are offering to pay startgas - maximum amount of gas allowed for the ...


20

The intrinsic gas for a transaction is the amount of gas that the transaction uses before any code runs. It is a constant “transaction fee” (currently 21000 gas) plus a fee for every byte of data supplied with the transaction (4 gas for a zero byte, 68 gas for non-zeros). These constants are all currently defined for geth in params/protocol_params.go. ...


12

I had to dig a little deeper into the contents of msg.data for this feature. I thought it would be worth noting that variable length parameters like arrays, bytes and strings produce a more complex structured msg.data. Given the following method: function getMsgData( address _address, bytes _bytes, uint _int, uint[] _array, string _string ) ...


11

As per the Solidity version 0.5.0 breaking changes here : Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. So currently, reference types comprise structs, arrays and mappings. If you use a reference type, you always have to explicitly ...


10

web3.eth.getTransaction has an input property, which is the /payload for a given transaction. The cost of a transaction is gasUsed multiplied by gasPrice. web3.eth.getTransactionReceipt has the gasUsed property. web3.eth.getTransaction has gasPrice. Since the unit for gasPrice is wei, divide by 1e18 to get the Ether cost of a transaction.


8

Use getData. Example: // Get the call data, so you can call the contract through some other means var myCallData = myContractInstance.myMethod.getData(param1 [, param2, ...]); // myCallData = '0x45ff3ff6000000000004545345345345..'


7

If the question is about abi params, you can take a look at these two web3.js files: https://github.com/ethereum/web3.js/blob/master/test/coder.encodeParam.js https://github.com/ethereum/web3.js/blob/master/test/coder.decodeParam.js Although these functions are not a part of public web3.js interface. Mostly because they need a proper refactor. There is ...


7

The data you're sending is part of the transaction, but it is not "added" to the account. There is storage associated with accounts (accessed via eth.getStorageAt(address,location)) but it will be empty unless a contract stores data there. Since the data is associated only with the transaction, not with the account, the best way to access it is to use ...


7

Generally, no! It can be dangerous. If you are asked to send such a transaction, you should understand what is the source code of the address you are sending to, and what function you might be invoking with the data you are sending. Do not send arbitrary data to some arbitrary address because that is like running an arbitrary program, clicking on an ...


6

In genesis.json you can set the block gas limit and then see How can I stop the block gas limit on a private chain dropping to the public chain default? Does it mean that I can transfer any amount of data between accounts and all of this gets stored in the private blockchain forever? Yes.


6

To use eth_call, the tricky part is providing the data, which is ABI encoding the function you want to invoke and its arguments. It's essential to use canonical types, so double(int256) instead of double(int). > web3.sha3('double(int256)').substr(0, 8) "6ffa1caa" Padding and dynamic types must be specified correctly. In this example the int256 argument ...


6

To keep the core protocol of Ethereum simple and generic, the protocol has the rule that a message always executes the code of an account. Simple and generic allows the critical consensus protocol to be smaller and decrease the risk of consensus bugs. This means that a detail, such as the Ethereum Contract ABI, does not need to be defined in the core ...


5

You need to allocate more gas to your transaction with the addDocument function. Mist is looking ahead and is able to tell that the transaction will fail because you haven't given the transaction enough gas to execute with.


5

There is something specifically for this purpose, which is called Whisper In a nutshell whisper is a communication protocol for DApps to communicate each other. Example Usage var shh = web3.shh; var appName = "My silly app!"; var myName = "Gav Would"; var myIdentity = shh.newIdentity(); shh.post({ "from": myIdentity, "topic": [ web3.fromAscii(...


5

Consider unlocking the account before sending the transaction: personal.unlockAccount(eth.accounts[0], 'your password goes here', 9000) or RPC call: curl your_ethereum_node_address:port -X POST --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params": ["your account address","password of your account",null],"id":1}' I was struggling quite some ...


5

Yes, although obviously each contract has to execute the call itself. You can do this 1024 times until you reached the maximum depth. At that depth all new calls will fail. This even lead to vulnerabilities in the past. That said, EIP-150 increased the gas cost of calls so much that you can't reach the maximum depth anymore.


5

memory and calldata (as well as storage) are keywords that define the data area where a variable is stored. To answer your question directly, memory should be used when declaring variables (both function parameters as well as inside the logic of a function) that you want stored in memory (temporary), and calldata must be used when declaring an external ...


4

In case you need an online tool to encode parameters to abi format you can use https://abi.hashex.org/. It has functionality to auto parse contract's abi to get function names and parameter types and provides convenient way to enter their values. Here is an example of using this service


4

The keyword payable is needed on a function. See solidity docs: Payable for functions: Allows them to receive Ether together with a call. So, this doesn't work: function transfer(address _to, uint256 _value) { This does work: function transfer(address _to, uint256 _value) payable {


4

The specification for msg.data is the Ethereum Contract ABI. Here's the code from the answer provided by Andreas: contract ReadConvertUint256Bytes { function equal(uint a) constant returns (bool) { uint x = 0; for (uint i = 0; i < 32; i++) { uint b = uint(msg.data[35 - i]); x += b * 256**i; } ...


4

Byte-per-byte comparisons. Conversions needed. reddit link is dead. Why do you need to access msg.data directly? EDIT: Convert a uint256 from calldata bytes to a proper uint256 in Solidity: https://gist.github.com/anonymous/a734a5d299ffa7b5a834 EDIT: The typing system and posting rules on this site are super weird. Anyways that works. It should always ...


4

The size of data field is dependent on the block gas limit. In the Ethereum public blockchain, the limit for the data field was 89kb as of Feb 7, 2016. Source. You can use a similar methodology to check for the limit now. However, In a private blockchain, there's no limit to the data field. You can set the block gas limit value in your genesis file. Source


4

Yes, all parameters can be accessed from msg.data (EVM term is calldata). The calldata is ABI encoded: What is an ABI and why is it needed to interact with contracts? Extracting the first parameter is simpler than others. For the first parameter, skip the first 4 bytes (Method ID), and the next 32 bytes is the uint (left-padded) you are looking for. If ...


4

Assume you have a solidity function inside your smart contract which accepts data in the form of e.g. an integer called xyz: function takeData(int xyz) Now in e.g. geth you can create an instance of that smart contract and call the function by: contractInstance.takeData.sendTransaction(12345, {from: web3.eth.accounts[0]}) You can find a complete walk-...


4

Yes, in web3.eth.sendTransaction({from: ..., to: addressOfE, data: something});, then in contract E, msg.data will be the something. However, most of the time a contract handles msg.data indirectly and easily. For example, if you have a contract instance in web3.js // creation of contract object var MyContract = web3.eth.contract(abi); // initiate ...


4

From Miguel Mota page, using Etherdelta ABI, and your transaction input I get { "name": "trade", "types": [ .. ], "inputs": [ "0", "16d8fceafcef3c0000", // <- amountGet "340d2bde5eb28c1eed91b2f790723e3b160613b7", "8b7363b040ca2bb600000", // <- amountGive "46eeac", "87d84d79", "...


3

IF the fallback function only gets 2300 gas, it can't write to contract storage and here are 2 ideas. Option 1 You could add an explicit function like receiveEther(string senderName) in the contract. web3.js can be used like contractInstance.receiveEther("name of the sender", {value: web3.toWei(1, "ether"), ...}) and the contract could access the sender ...


3

The general answer is that it follows the conventions of the ABI. You can work it out based on those rules. In this particular case, the encoding of data will start at position 36. The first four bytes will be the message signature, and the next 32 will be a pointer to the location of data's representation. Note that the first 32 bytes of data will give ...


3

msg.data is usually ABI encoded information that indicates to the contract the function and parameters to invoke. Using standard tools, msg.data will be the same if the contract is called with the same parameters. However, hashing it with the block.number as in sha3(msg.data, block.number) will produce a completely different result, for each block. Note: ...


Only top voted, non community-wiki answers of a minimum length are eligible