Deploying contract using byteCode (MyEtherWallet and Remix).

Prashant Prabhakar Singh
Sofocle Technologies
4 min readNov 19, 2017

So you wish to deploy a smart contract but your node is not synced. Don’t worry you need not to wait to sync your node. There are alternatives to deploy your smart contract. The one we are going to discuss is deploying smart contract using byteCode with MyEtherWallet.

Have you heard about myetherwallet ? If no, go have a look, get familiarized.

# What you need to deploy smart contract using myEtherWallet?

  • Your solidity code
  • An account with some ethers
  • geth console (metamask injects web3 so that will also be fine)
  • Internet connection 😉

# Compile your contract using remix.

Remix is a very powerful compiler for solidity, you can use remix to compile, test and even deploy a smart contract. But here we’ll use remix only as a compiler.

Paste your smart contract code in Remix and compile the smart contract. Click on start to compile to compile your smart contract.

Smart Contract in remix

We need 2 things from the compiled smart contract, ABI, and byteCode.

Choose the contract name that we want to deploy from the left dropdown and click on the details tab. You will see the bytecode and ABI while you scroll down the details.

details tab of smart contract.

Copy the byteCode and ABI by clicking on the copy to clipboard.

# Passing arguments to the constructor of smart contract

You must be wondering, we didn’t yet pass arguments to the constructor of smart contract. This is now we are going to do next and this is the key part of this story. We need geth console to get the complete byte code. Just go to your geth console and type following commands:

var abi = abi_provided_by_remix;
var rowByteCode = "byte_code_provided_by_remix";
var myContract = eth.contract(abi);
var byteCodeWithParam = myContract.new.getData(param1,param2,{data: rowByteCode});

Note: Pass the constructor arguments in the same order as you declared in the constructor.

For eg, if you constructor looks like:

function BasicToken (string _name, uint _totalSupply, uint _initialSupply,  uint _decimals) public {
owner = msg.sender;
....
}

You need to get bytecode by passing arguments in the same order:

var byteCodeWithParam = myContract.new.getData("Test Token", 21000000, 1000000, 4, {data: rowByteCode});

# Deploy the byteCode using myEtherWallet

  • Go to the contacts tab of myEtherWallet.
  • Click on deploy contract.
  • Paste the byteCodeWithParam into the byteCode textBox. If the bytecode is correct, the box will become green, else red
  • If box borders red, you need to check your steps, else proceed further.
Deploying using byetCode
  • The gas Limit box is filled automatically. You can change/update this value, but we sure to provide enough gas so your transactions don’t run out of gas.
  • You can also change the gas price that you are willing to pay per gas. The default gas price is 21Gwei.
  • Also make sure, in the Network selected to be: ETH (MyEtherWallet).
Network and Gas Price in MEW
  • To deploy the byte Code, you need to unlock your account and send Transaction.
  • There are multiple possible methods to unlock your account including using Private key, KeyStore file and so on. Choose any of the methods.
  • When your account is unlocked successfully, you see a Sign Transaction button.
  • Once you click this button, you’ll see two text boxes with Raw Transaction and Signed Transaction and a Deploy Contract button below that.
Deploy contract button.
  • Click on Deploy Contract button to deploy your contract. You will be asked for confirmation, just click Okay (Yes I’m sure make the transaction) button.
  • Woohoo... The transaction is sent on the blockchain. You will immediately see the transaction hash. Copy the transaction hash and check the status on etherscan.

Congratulations, you have successfully deployed the smart contract. Cheers!

--

--

Prashant Prabhakar Singh
Sofocle Technologies

Team lead at @SofocleTechnologies (www.sofocle.com) #Ethereum Developer #Blockchain Enthusiast