I have been working with solidity and contracts for a while, but a question came to my mind.

Currently, when you want to interact with a contract using javascript (as example), you need to do the folowing:

var code = fs.readFileSync(solidityFile).toString();
// Compile the contract code
var compiledCode = solc.compile(code);
// Generate the ABI 
abi = JSON.parse(compiledCode.contracts[':SupplyChainContract'].interface);
contractInstance = new web3.eth.Contract(abi, contractAddress);

This generates a contract instance and you use this instance to call functions of contract and send transactions.

But, why do we need to do this?

Why cannot we just use the contract address and ask it to execute a function with given parameters? Is it to prevent spam? To force accountUnlock?

Edit: Is it to save state on the node before the state after transaction if validated (or not)? Forget that, does not seem to make sense.

  • If you only have an address you don't have the ABI. How do you know what functions exist? You know it because you wrote the contract, but to other people it's just a bunch of byte codes. Commented Nov 13, 2017 at 3:22

1 Answer 1


The web3js library provides this abstraction as a convenience to you, the programmer, so that you don't have to deal with the complexities of the lower-level JSON RPC API.

I believe, that you could use web3js's sendTransaction function - and then provide the "to" value as the address of the contract in the "transactionObject", but then instead of relying on web3js to work out the "data" byte array parameter of the "transactionObject" then you would have to determine this yourself.

In short, the web3js contract instance is doing a fair amount of heavy lifting for you - and abstracting away these necessary steps, so that in the future if they were to change that the work required from your end (and any other developing using this library) would be minimal; both of which are desirable features from a library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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