0
import Web3 from "web3";
import Registry from "./contracts/Registry.json";
import Resolver from "./contracts/Resolver.json";
import Cache from "./contracts/Cache.json";
import trufflemigration from "./contracts/Migrations.json";
import React from "react";
import { useState, useEffect } from "react";
import  "./App.css";

function App() {
  const [state, setState] = useState({ web3: null, contracts: {} });

  useEffect(() => {
    const provider = new Web3.providers.HttpProvider("http://127.0.0.1:7545");

    async function template() {
      const web3 = new Web3(provider);
      const networkId = await web3.eth.net.getId();
      const registryDeployedNetwork = Registry.networks[networkId];
      const resolverDeployedNetwork = Resolver.networks[networkId];
      const cacheDeployedNetwork = Cache.networks[networkId];
      const trufflemigrationDeployedNetwork = trufflemigration.networks[networkId];

      const registryContract = new web3.eth.Contract(Registry.abi, registryDeployedNetwork.address);
      const resolverContract = new web3.eth.Contract(Resolver.abi, resolverDeployedNetwork.address);
      const cacheContract = new web3.eth.Contract(Cache.abi, cacheDeployedNetwork.address);
      const trufflemigrationContract = new web3.eth.Contract(trufflemigration.abi, trufflemigrationDeployedNetwork.address);

      setState({
        web3: web3,
        contracts: {
          registry: registryContract,
          resolver: resolverContract,
          cache: cacheContract,
          trufflemigration: trufflemigrationContract
        }
      });

      // To interact with smart contracts, you require the API and contract address.
    }

    provider && template();
  }, []);

  console.log(state);

  useEffect(() => {
    const { registry, resolver, cache, trufflemigration } = state.contracts;

    async function writeData1() {
      const data = await registry.methods.updateIp( string message  ,uint256 value   ).send({ from: "0xD21ffdb9136E67B4bF6bd18f9Fb915A87e47e16c" });
      console.log(data);
    }

    async function writeData2() {
      const data = await registry.methods.register( string message   ,   uint256 value  ).send({ from: "0xD21ffdb9136E67B4bF6bd18f9Fb915A87e47e16c" });
      console.log(data);
    }



    async function readData1() {
      const data = await resolver.methods.resolve().call();
      console.log(data);
    }

    async function readData2() {
      const data = await cache.methods.resolve().call();
      console.log(data);
    }

    async function writeData3() {
      const data = await cache.methods.updateCache( bytes32 indexed nameHash  , bytes ip  ).send({ from: "0xA64C7c25153Bece2ad692731a0b61858F64808c2 " });
      console.log(data);
    }

    async function readData3() {
      const data = await trufflemigration.methods.setCompleted().call();
      console.log(data);
    }

    async function readData4() {
      const data = await trufflemigration.methods.setCompleted().call();
      console.log(data);
    }

    registry && writeData1();
    registry && writeData2();
    resolver && readData1();
    cache && readData2();
    cache && writeData3();
    trufflemigration && readData3();
    trufflemigration && readData4();
  }, [
    state.contracts,
    state.contracts.registry,
    state.contracts.resolver,
    state.contracts.cache,
    state.contracts.trufflemigration
  ]);
   
  return (
    <div className="App"></div>
  );
}
export default App;
1
  • this my graduation project, i am really need help Commented Mar 25 at 20:37

0

Your Answer

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

Browse other questions tagged or ask your own question.