193

Call A call is a local invocation of a contract function that does not broadcast or publish anything on the blockchain. It is a read-only operation and will not consume any Ether. It simulates what would happen in a transaction, but discards all the state changes when it is done. It is synchronous and the return value of the contract function is returned ...


85

DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the sending contract which needs to trust that the receiving contract will treat the storage well. DELEGATECALL was a new opcode that was a bug fix for CALLCODE which did not preserve msg.sender and ...


63

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 ...


39

The difference between in a call and a transaction is the following: transactions are created by your client, signed and broadcasted to the network. They will eventually alter the state of the blockchain, for example, by manipulating balances or values in smart contracts. calls are transactions executed locally on the user's local machine which alone ...


35

At present the user initiating the transaction must pay the fee. However Serenity is likely to enable 'contract pays' schemes. (See Vitalik's blog post here) A possible work around is a contract which refunds the sender however this would still require the user to hold some Ether and might allow malicious parties to repeatedly call the contract to deplete ...


34

It is not currently possible to return values from functions which modify the blockchain. To receive a return value, you can mark functions as "pure" or "view". For state-changing functions, the only way to "return" information is by using Solidity Events, which coalesce as LOG opcodes in the Ethereum Virtual Machine.


33

Update per @Girish comment, in Solidity 0.6+ the syntax has changed to: address.function{value:msg.value}(arg1, arg2, arg3) Original The general syntax for calling a function in another contract with arguments and sending funds is: address.func.value(amount)(arg1, arg2, arg3) func needs to have the payable modifier (for Solidity 0.4+). Completing @Edmund'...


27

Here is a snippet of D using delegatecall on E from Difference between CALL, CALLCODE and DELEGATECALL contract D { uint public n; address public sender; function delegatecallSetN(address _e, uint _n) { _e.delegatecall(bytes4(keccak256("setN(uint256)")), _n); // D's storage is set, E is not modified } } contract E { uint public n; address ...


24

There are a few types of string values that you may be referring to. bytes1 - bytes32: fixed size. bytes or string: dynamically sized. Solidity supports functions with multiple return values. contract MultiReturner { function getData() constant returns (bytes32, bytes32) { bytes32 a = "abcd"; bytes32 b = "wxyz"; return (a, b); ...


24

Yes. The internal modifer means that the function can only be called within the contract itself and any derived contracts. private functions are not available in derived contracts. From the docs: internal: Those functions and state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using ...


23

No, a sender with zero ether cannot "ask" a contract to pay for the gas costs. A sender with zero ether cannot even send a transaction. More details: The sender of a transaction must have enough gas to cover execution of the transaction. That gas is required even before a contract can even be called. Once the gas requirement is met (so that the ...


23

result is a BigNumber object that is stringified to something like { [String: '5'] s: 1, e: 0, c: [ 5 ] }. You can use BigNumber methods, like result.toNumber() to see it better. When integers are involved, web3.js uses BigNumber because native Javascript numbers are not large enough. It's out of scope here to go into the internals of a general external ...


23

Use an abstract contract (preferred) Further clarifications to @Edmund's answer: contract A { // This doesn't have to match the real contract name. Call it what you like. function f1(bool arg1, uint arg2) returns(uint); // No implementation, just the function signature. This is just so Solidity can work out how to call it. } contract YourContract { ...


20

The internal modifier can be better compared with protected in object-oriented programming languages. Internal functions of the contract C are visible to the code running at the current address (i.e. the current contract instance) but also to contracts derived from C. Note that due to the architecture of the EVM, visibility is something that can be strictly ...


19

Yes, the answer is quite logic. Every node has to verify the results of a transaction which invokes a smart contract. The result is that at least every full node will execute the code. The hash of the transaction isn't relevant until it is being stuffed into a merkle tree. When running the execution, all we care about is the amount of gas, the data being ...


18

There are estimateGas APIs in both the JSON-RPC and Javascript. They are estimates and for developers that want further precision, testing is required, possibly on a private chain. If too much gas is provided, the excess gas is converted to ether and refunded. If too few gas is specified, all the specified gas is forfeited to the miner and the transaction ...


18

In order to send Ether to another contract while specifying the amount of gas, use the call function. targetAddress.call.gas(200000).value(this.balance)(); will call the fallback function. targetAddress.call.gas(200000).value(this.balance)(bytes4(sha3("pay()"))); will call the pay function.


17

The total cost of a transaction that creates a contract or executes a contract is based on 2 factors: gasUsed is the total gas that is consumed gasPrice specified in the transaction Total cost = gasUsed * gasPrice gasUsed Each operation in the Ethereum Virtual Machine (EVM) was assigned a number of how much gas it consumes. gasUsed is summing up all ...


17

You can do: /* MORTAL CONTRACT HERE */ contract Name is mortal{ mapping(address=>string) public text; string public test; function register(string _text){ text[msg.sender] = _text; } } contract Proxy is mortal { address watch_addr = 0xEB1e2c19bd833b7f33F9bd0325B74802DF187935; address user_addr = msg.sender; ...


17

If the deployed contract doesn’t adhere to the ABI, but you know the contract signature (name and argument types) You could use : contract_address.call(bytes4(sha3("function_name(types)")),parameters_values) for example : contrac_A.call(bytes4(sha3("f()")) while there is no input no parameters in your exemple. replace contract_address,function_name,...


16

They will run out of gas. Each smart contract can only be invoked by a transaction. Transactions costs fees and executing contracts costs gas, which are a kind of additional fees for each executional step. If one smart contract calls another contract, it has to create a new transaction which only works if the contract has access to enough ether to pay the ...


16

What happens if Bob, Alice and Eve all call the Greeter at the same time and all three calls are in the same block? The three transactions would get called, not necessarily in sequence, and the last transaction's name will be persisted in the mined block. Does everyone get the proper response with their own name? No. The getName() method would return the ...


16

Functions (aka Methods) are specified by the ABI, and have a Method ID, which is the first 4 bytes of the sha3 (Keccak-256) of the method's signature. Here's an example of invoking someFunction on contract: contract.call(bytes4(sha3("someFunction()"))) Here is a tested function with passing a methodId as a parameter: contract C1 { uint public _n; // ...


15

Transactions are executed purely sequentially, in an order set arbitrarily by the miner who wins each block. Higher gas priced transactions are more likely to make it into a block, so that contributes to order as well, at the discretion of the miner. Note that each miner chooses separately, but only one miner wins a round. The winning miner determines the ...


14

EDIT Dec 2019: call.value()() should now be used for transferring ether. (Do not use send or transfer.) See: Is transfer() still safe after the Istanbul update?


14

The protocol requires that transactions from a single account are executed in nonce order. It's still possible for an account to have many pending transactions, and as long as the nonces are contiguous, a miner can include as many of them as desired in a single block, as long as they're executed in order. There's no guarantee of ordering of transactions ...


14

This process works as follows: You must compile the same exact code that the contract you are trying to load. Once the compile succeeds, you have to be on the same network that the contract is, by setting your MetaMask account propperly. The last thing to do is paste the contract address on the option: Load from address: and you'll get it on remix to ...


13

Seems like the contract address should be enough. You're right, it would be better if the ABI could be obtained by just looking at the contract. So why do contract writers need to also provide the ABI, in addition to the contract address? One reason is that the function Method IDs in a contract are computed using a hash function. So it is infeasible for ...


13

Here's an approach that's simpler and checked by the compiler: contract contractA { function blah(int x, int y) payable {} } contract contractB { function invokeContractA() { contractA a = contractA(0x1234567891234567891234567891234567891234); uint ValueToSend = 1234; a.blah.value(ValueToSend)(2, 3); } }


13

Yay, found it in solidity docs in FAQ section: What is the deal with function () { ... } inside Solidity contracts? How can a function not have a name? This function is called “fallback function” and it is called when someone just sent Ether to the contract without providing any data or if someone messed up the types so that they tried to call a ...


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