Skip to main content
Share Your Experience: Take the 2024 Developer Survey
82 votes

Hardhat - How to interact with a deployed contract?

I ran into the same question and stumbled upon a section in the OpenZeppelin docs that may work for you (it did for me): For example: const MyContract = await ethers.getContractFactory("...
julianwyz's user avatar
  • 966
65 votes
Accepted

How to write an optimized (gas-cost) smart contract?

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 can be found as explained in ...
Achala Dissanayake's user avatar
50 votes

What is the real price of deploying a contract on the Mainnet?

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 ...
natewelch_'s user avatar
  • 12.1k
39 votes
Accepted

How to update a deployed smart contract?

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, ...
Matthew Schmidt's user avatar
31 votes
Accepted

truffle migrate: How to deploy a contract whose constructor takes a parameter

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 ...
Ismael's user avatar
  • 30.5k
31 votes

Hardhat - How to interact with a deployed contract?

hardhat-ethers ^2.0.0 has a special function getContractAt for exactly this purpose: const contractAddress = "0x...", const myContract = await hre.ethers.getContractAt("MyContract",...
Chris's user avatar
  • 459
30 votes
Accepted

having a problem with solc-x version "solc 0.6.0 has not been installed"

I'm working through this same course check this out and it will show you how to fix this error here: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/blob/main/chronological-...
Ellsready's user avatar
  • 316
29 votes

Truffle deployment on test network says: Error: exceeds block gas limit

Inside truffle.js, add ,gas: 4600000 Don't forget the little "," so it looks like networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: ...
Russo's user avatar
  • 1,784
28 votes
Accepted

How to get Source code of an already deployed contract?

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 ...
mKoeppelmann's user avatar
  • 7,626
27 votes

Calling function from deployed contract

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, ...
eth's user avatar
  • 85.9k
25 votes
Accepted

At which point the smart contracts get executed?

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 ...
gnidan's user avatar
  • 406
24 votes
Accepted

How to pass constructor parameters to a contract using Truffle?

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"
Rob Hitchens's user avatar
  • 55.3k
23 votes
Accepted

What's the difference between solc's bin bytecode versus bin runtime?

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, ...
Thorkil Værge's user avatar
22 votes
Accepted

How to generate a vanity address for a smart contract to be deployed on?

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 ...
Nick Johnson's user avatar
  • 8,174
21 votes

How is the address of an Ethereum contract computed?

Thanks to eth's answer, it helped 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. ...
k06a's user avatar
  • 3,036
20 votes
Accepted

How to choose an account to deploy a contract in truffle

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:...
rstormsf's user avatar
  • 4,357
19 votes
Accepted

When a smart contract is deployed, is its source code publicly viewable?

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 ...
Edmund Edgar's user avatar
  • 16.9k
19 votes
Accepted

Deploying contract with constructor arguments via Geth RPC

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 ...
BokkyPooBah's user avatar
  • 40.3k
18 votes
Accepted

Calling function from deployed contract

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)")),...
Badr Bellaj's user avatar
  • 18.8k
16 votes
Accepted

Deploying the Greeter contract via the geth CLI is not registering in my private blockchain

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 ...
BokkyPooBah's user avatar
  • 40.3k
16 votes

How to edit a contract that has already been deployed?

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 ...
JackWinters's user avatar
  • 3,423
15 votes
Accepted

How to deploy smart contract in predefined contract address in private ethereum network?

It is not possible to deploy a contract to an address of your choice The address a contract is deployed to is generated deterministically using the address of the deployer and the deployer's total ...
Joe's user avatar
  • 1,183
15 votes
Accepted

How to get the contract ABI in new Remix IDE?

I cannot find the contract details to get the json interface anymore. If you select the compile tab, there you will find a button called details. When the details is clicked, a pop-up window will ...
Achala Dissanayake's user avatar
15 votes
Accepted

How to deploy contract with ether.js

You can deploy a contract using Ethers.js' ContractFactory. import { ContractFactory } from 'ethers'; const factory = new ContractFactory(contractAbi, contractByteCode); // If your contract requires ...
Morten's user avatar
  • 6,017
14 votes
Accepted

Why does this Oraclize query only works once?

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 ...
Thomas Bertani's user avatar
14 votes
Accepted

Bytecode on block chain different from the one used when deploying

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 ...
eth's user avatar
  • 85.9k
14 votes
Accepted

How big could a contract be?

Solidity contracts are compiled to EVM bytecode. Contract bytecode costs 200 gas per byte of bytecode, and since block gas limit is 8 million right now, you could theoretically get a ~40,000 (a little ...
natewelch_'s user avatar
  • 12.1k
13 votes

How is the address of an Ethereum contract computed?

Here's a node.js script that deterministically computes an Ethereum contract address given the contract creator's public address and nonce value. Let me know if anyone has questions about inputs, etc. ...
kawthuldrok's user avatar
13 votes

How to Compile and Deploy a Smart Contract without running a full node?

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 ...
Victory's user avatar
  • 1,231
12 votes
Accepted

Return Token Contract address on truffle deploy

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)...
David Young's user avatar

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