1
votes

In order to deploy a smart contract to the network we need three the following informat:

From web3 spec:

// deploy new contract
var contractInstance = MyContract.new([constructorParam1] [, constructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});

Correct me if I am wrong:

constructorParams - all the data that is passed to the smart contract constructor,

from - determines the address this contract is deployed from

gas - gas limit on how much this transaction can consume

What is data, is it sort of a compiled solidity code of the contract, if so why then do we need it if we have already specified ABI of this contract?

How do I get this data parameter? I also get an error in my console when I try to deploy the contract to the network without specifying data parameter:

Error: "invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field SendTxArgs.data of type hexutil.Bytes"

2

2 Answers

2
votes

Yes, data is the compiled byte code for your smart contract.

The ABI doesn't have the code for running the contract; it just describes the interface (what functions exist with what parameters).

You get the bytecode from the compiler. Without knowing what tool you're using, it's hard to be more specific.

0
votes
const data = contract.methods.contractFunction(contractArgument).encodeABI()

This will encode a function of the contract into byte code, which can then be passed into the data parameter.

contractFunction(contractArgument)

will be different for you and the function you are wanting to call.