I am building a react application using web3 to interface with Ethereum. At a bare minimum, it needs to create a contract, deploy said contract, store a value (i.e. a string: "test"), then later retrieve that value.

All this needs to happen in the React application and on the ethereum network. No test networks, no outside tools to deploy the contract.

I can't seem to find a reference on how to accomplish this, for what is really a simple task. All tutorials I could find focus on Ganache or Truffle and use outside means to deploy the contract...


1 Answer 1


You are conflating tooling and platform.

Truffle is tooling. You don't deploy to truffle, but it can be handy to use truffle to deploy to dev/test and production platforms.

Ganache is platform. Regardless of tooling (in your case, a React app), Ganache is a valid platform for dev/test both in terms of cost and in terms of developer productivity. Consider using that as you iterate over your React app.

You should probably consider platform dependencies for your React app. Will you proceed on the assumption that users have a full node nicely synced up, do you want to minimize dependencies or do you want to offer a choice? You'll need a Web3 "provider". If you so choose, you can have multiple providers conditionally chosen at runtime, i.e. Look for full node or fall back to Infura if there is no full node.

Deploying a contract involves a specially crafted transaction, signed by the deployer and sent to address 0x0. In the simple case, it's the same contract every time, so you can compile it outside your app and treat the bytecode to deploy as data known to the app. A JavaScript app can compile source code on-the-fly if you need that instead.

Web3 itself has gone through significant changes, so many of the examples found online are outdated. I did some searching for a recent example with reasonably concise code. This node example seems appropriate and hopefully, you can extrapolate from that for your React implementation. I realize it's an issue report.


Hope it helps.

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.