2

I have developed a smart contract and compiled it with solc and bin and abi fils have been generated. Now, I want to deploy this contract using web3js in a linux server. How can I do it?

  • you can setup a private chin or a single geth node in your server. otherwise use ropsten network thorough metamask or myethewallet. – Badr Bellaj Apr 10 '18 at 10:48
  • @ Badr Bellaj Thank you, but could you tell me how to setup a single geth node in server ? also, Do I need to install web3 i.e. npm install web3 ? – Questioner Apr 10 '18 at 11:06
  • as you are new to the field, if you want just to test your code try to use instead testrpc or truffle. ethereum.stackexchange.com/questions/23842/… – Badr Bellaj Apr 10 '18 at 11:08
  • @ Badr Bellaj Yes I am new to this field, but I have to deploy it in server. I fouhttps://ethereum.stackexchange.com/users/2021/badr-bellajnd a javascript file that is apparently for deploying the contract gist.github.com/tomconte/4edb83cf505f1e7faf172b9252fff9bf but question is that how to use this file in server ? Thanks – Questioner Apr 10 '18 at 11:16
0

so in a nutshell :

first: deploy a geth node in your server. here's a detailed tutorial https://medium.com/mercuryprotocol/how-to-create-your-own-private-ethereum-blockchain-dad6af82fc9f

second: once your node is running use Remix, connect it to your node RPC address and deploy directly from remix.

otherwise you can explore the solutions described in my comments to your post.

0

To deploy a smart contract on ethereum, you have to make a deployment transaction.

A deployment transaction is send contract bytecode to empty address.

For example:

My add.sol

pragma solidity 0.5.1;


contract ADD {
    uint256 total;

    function add(uint256 a, uint256 b) public {
        total = a+b;
    }
}

The bytecode of add.sol 608060405234801561001057600080fd5b5060b88061001f6000396000f3fe6080604052600436106039576000357c010000000000000000000000000000000000000000000000000000000090048063771602f714603e575b600080fd5b348015604957600080fd5b50607d60048036036040811015605e57600080fd5b810190808035906020019092919080359060200190929190505050607f565b005b808201600081905550505056fea165627a7a72305820e3f9b94abc880b4f5646678c218c6c79a98f8dad3a566a9822548d539b741a340029

The deployment transaction looks like:

{
    from: "0x......", // you have to unlock account first
    to: null,
    gas: 2000000,
    gasPrice: 1000000000,
    value: 0,
    data: "0x60806040523480156......"
}

You can call send transaction rpc through curl:

curl -vX POST localhost:8545 -d '{"method": "eth_sendTransaction", "id": 1, "params": [{"transaction object"}]}' -H "Content-Type: application/json"

Alternative you can call send raw transaction rpc if you want to sign with own private key:

curl -vX POST localhost:8545 -d '{"method": "eth_sendRawTransaction", "id": 1, "params": ["0x................."]}' -H "Content-Type: application/json"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.