1

I am creating a simple registration and login forms in React.js and connecting it with smart contract in order to use it to store the data from the front and to the blockchain is there any method or command to connect the front end with the smart contract in order to use its functions?

Thank in advance

2 Answers 2

1

There are many tuts how to do this basically its as simple as that

import Web3 from 'web3';

let rpcUrl = "https://mainnet.infura.io/ocCdekUYwOyLn7h7OlJM";
let web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl));

const contractabi = JSON.parse('abi.json'); // the ABI
const contractaddress = '0xb51adbdd256930bd6b4c613add6fcca31db49827'; // Address of contract
const myContract = web3.eth.Contract(contractabi , contractaddress);

myContract.methods.getXY().call();
myContract.methods.setXY("bitsofcode").send();

Take a look at these examples :

https://bitsofco.de/calling-smart-contract-functions-using-web3-js-call-vs-send/

https://developer.ibm.com/recipes/tutorials/working-with-web3js-api-and-json-to-build-ethereum-blockchain-applications/

1

If you're doing this programmatically, then you can check this repo in Stephen Grider's github account...

https://github.com/StephenGrider/EthereumCasts/tree/master/kickstart

It is for his udemy tutorial on blockchain development: "Ethereum and Solidity: The Complete Developer's Guide"

(the dependencies are a bit outdated, but it'll give you the idea)... and hopefully it helps!

If you happen to check it... and get confused anywhere... you can ask here! I'll try to answer to the extent of my knowledge! :D

1
  • 1
    ohh... you can check other projects in the repo EthereumCasts too... kickstart is one of those projects... lottery project too has a similar structure...! Commented Jul 27, 2020 at 11:47

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.