90

EDIT April 2019: CREATE2 information added. The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256. From pyethereum: def mk_contract_address(sender, nonce): return sha3(rlp....


44

In Ethereum transactions cost gas and hence ether. The gas consumption of a transaction depends on the opcodes that the EVM has to execute. The gas cost for each Opcode and be found as explained in this question. Few common opcodes and gas are, Operation Gas Description ADD/SUB 3 Arithmetic operation MUL/DIV ...


41

Yes, contracts have nonces. EIP 161 made the contract nonce start at 1, and before EIP 161 the nonce would start at 0. A nonce of a contract is only incremented when that contract creates another contract (@zanzu's YP reference). When a contract invokes a function on another contract, a so called "internal transaction" (in http://live.ether.camp), the ...


34

AFAIK the best way to do this at the moment is to compile the source code again with the exact same compiler version the author used (so this is something that needs to be disclosed) and to compare the bytecode. So the match you should check is the compiled bytecode against the data of the contract creation tx.


31

Contract code is permanent. There is no way to alter the code of a deployed contract except by destroying it altogether by the SELFDESTRUCT opcode (selfdestruct() in solidity.) There's four ways, more or less, to cope with this: Don't. Just have the contract be eternal, no matter what happens. Use some scheme to work around this limitation. Create a new ...


28

Inside truffle.js, add ,gas: 4600000 Don't forget the little "," so it looks like networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: 4600000 }


25

The cost of your deployment is based on 5 things, with a 6th affecting the estimated cost of deployment: The flat fee of 32k gas. The CREATE op code, which is called during contract creation, costs a fixed 32k gas. This is of course on top of the 21k gas of a normal tx. Note: During contract creation from an EOA (non-contract address), the CREATE opcode isn'...


23

There is no general solution for this because the solidity code is not published on the blockchain. On the blockchain only the resulting byte code is published. There are different block explorers like ether.camp that offer the option to upload the solidity code. They can use the solidity code to verify that it indeed matches with the byte code on the ...


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


23

When does it run? The execution for a smart contract transaction occurs when the mining node includes the transaction in a block it generates. The transaction and smart contract code is re-run by every validating node upon receipt of the block. Mining nodes, to generate a block: Receive unconfirmed transactions from the network (p2p protocol) Validate ...


20

The Greeter tutorial covers a basic Hello World contract. https://ethereum.org/greeter As a quick summary, I just tested the following steps on Ubuntu 14.04. The install-geth script should also detect and work on other environments. Note: I had to run the installation script in the first step below twice as it failed the first time. Install geth: bash &...


19

To add to @thomas-bertani's answer, today etherchain.org released a verification tool for Ethereum contracts Here's the text from the page: Source code verification provides transparency for users interacting with smart contracts. By uploading the source code, Etherscan will match the compiled code with that on the blockchain. Just like contracts, ...


19

It is quite complicated to get this correct, but here's some information on how to work it out. I'm using a simple contract as an example: pragma solidity ^0.4.2; contract Test { uint256 public v1; string public v2; function Test(uint256 _v1, string _v2) { v1 = _v1; v2 = _v2; } } Here is my deployment to a --dev blockchain ...


16

Update Apr 23 2017 geth 1.6.0 has a breaking change to remove access to the Solidity compiler from within geth. The workaround is detailed in How to compile Solidity contracts within geth with the v1.6.0 **BREAKING CHANGE**? Update Feb 04 2017 Solidity 0.4.9 has a breaking change. The workaround is detailed in Unable to define greeterContract in the ...


16

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

In Truffle, constructor params go in /migrations. So, something like: deployer.deploy(User, "foo"); User.deployed() will be a User contract that was deployed with _name="foo"


16

TL;DR bin-runtime is the code that is actually placed on the blockchain. The regular bin output is the code placed on the blockchain plus the code needed to get this code placed on the blockchain, the code of the constructor. Longer answer The basics of the Ethereum Virtual Machine is defined in Section 9.1 of the Ethereum Yellow Paper. To answer this ...


14

Thomas from Oraclize here. You probably are having this issue because you are not sending any value along. The Oraclize API calls come at a cost, the small fee we charge is paid in advance when calling oraclize_query. The first API call from each contract is free, so this is why your first call is working. Please check out our pricing here. This applies to ...


14

The short answer is that contract code is immutable so you can't update without destroying the contract and deploying a new one in which case any state will be lost and users, other contracts or user interfaces will need to interact with another contract. However there are various patterns which allow you to point to a new version and optionally keep state ...


14

I figured it out. in truffle.js you can specify from: field like this: // Allows us to use ES6 in our migrations and tests. require('babel-register') module.exports = { networks: { development: { host: 'localhost', port: 8545, network_id: '*', // Match any network id from: '0xA21983B35C767CF8609D95F4886C9A18A194D8AA' } } ...


14

You can add the constructor parameters as extra arguments to the deploy() call const BaconMaker = artifacts.require('./BaconMaker.sol') module.exports = (deployer, network, accounts) => { const userAddress = accounts[3]; deployer.deploy(BaconMaker, userAddress) } In your case since Farm will create BaconMaker on demand, you do not have to deploy ...


13

The answer to your question can be found in the yellow paper: nonce: A scalar value equal to the number of trans- actions sent from this address or, in the case of accounts with associated code, the number of contract-creations made by this account Remember: in Ethereum, contracts are accounts with code associated with them.


13

No, the source code isn't automatically publicly viewable. If you have a publicly usable smart contract then you normally need to publish it so that people will know what they're interacting with, but it doesn't happen automatically. The compiled bytecode is on the blockchain, though. It's hard to read but it's not safe to assume somebody won't work out ...


11

Thanks to eth's answer, it helps a lot to resolve $2000 issue. Just solved issue with funds, which were sent in main Ethereum network to address of smart contract, deployed to test Ethereum network. We used same wallet to deploy different smart contract in main Ethereum network several times until transaction field nonce achieved the same value 13, as were ...


11

Currently the workflow is quite annoying. You need to compile the contract with the same compiler version and the same setting (look out for the "optimization=true" flag). Now please note that the resulting bytecode does NOT match with the bytecode that is stored on the address. The reason for that is that the compiled contract does contain an ...


11

The address of the contract is just the variable name of the deployed contract. Try this: deployer.deploy(CrowdTestToken).then(function(){ return deployer.deploy(CrowdSale, CrowdTestToken.address)});


11

Install https://metamask.io/ and Navigate to https://remix.ethereum.org/ Click on settings -> choose your compiler (e.g. 0.4.19+commit.c4cbbb05). Note that optimization is unchecked. Login to metmask and choose your network (i would suggest first testing using ropsten test network and using the buy button to get ETH from a free faucet) Go back to the compile ...


10

Yes, it is normal and the code on the blockchain is always a subset of the compiled (byte)code, because the compiled code includes initialization code. The compiled code is/executes a function which returns the blockchain code, but as part of the execution also initializes the contract being deployed. For your contract, look at its transaction 1 and you ...


10

Possible it's not unlocked long enough? web3.personal.unlockAccount(web3.personal.listAccounts[0],"password",15000); // 1st account, pw & time in seconds ...


10

Generating a vanity address is a simple process of trial-and-error, and the same process can be used to search for accounts having some other property. Contract addresses are determined by the account of the creating account and its nonce - specifically, they're the hash of the RLP encoding of those two values. Thus, you can search for an account that ...


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