Skip to content

Instantly share code, notes, and snippets.

View wissalHaji's full-sized avatar

Wissal Haji wissalHaji

View GitHub Profile
@wissalHaji
wissalHaji / App.js
Last active February 8, 2021 18:22
import React, { useEffect, useState } from "react";
import { useDrizzleContext } from "./drizzle/drizzleContext";
import { connect } from "react-redux";
function App({ dataCall, account }) {
const drizzle = useDrizzleContext();
const [data, setData] = useState("");
const [cacheKey, setCacheKey] = useState(null);
import React from "react";
import { connect } from "react-redux";
const LoadingContainer = ({ web3, accounts, initialized, children }) => {
if (initialized) {
if (web3.status === "failed") {
return (
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { DrizzleProvider } from "./drizzle/drizzleContext";
import { Provider as ReduxProvider } from "react-redux";
import options from "./drizzle/drizzleOptions";
import { Drizzle, generateStore } from "@drizzle/store";
import logger from "redux-logger";
const store = generateStore({
import React, { createContext, useContext } from "react";
const Context = createContext();
export function DrizzleProvider({ drizzle, children }) {
return <Context.Provider value={drizzle}>{children}</Context.Provider>;
}
export function useDrizzleContext() {
const context = useContext(Context);
const Web3 = require("web3");
const EventExample = require("../build/contracts/EventExample.json");
const init = async () => {
const web3 = new Web3("ws://localhost:7545");
const id = await web3.eth.net.getId();
const deployedNetwork = EventExample.networks[id];
const eventExample = new web3.eth.Contract(
EventExample.abi,
const displayGreeting = async (greeting, contract) => {
greeting = await contract.methods.sayHello().call();
$("h2").html(greeting);
};
const updateGreeting = (greeting, contract, accounts) => {
let input;
$("#input").on("change", (e) => {
input = e.target.value;
});
const getContract = async (web3) => {
const data = await $.getJSON("./contracts/Greeting.json");
const netId = await web3.eth.net.getId();
const deployedNetwork = data.networks[netId];
const greeting = new web3.eth.Contract(
data.abi,
deployedNetwork && deployedNetwork.address
);
return greeting;
const getWeb3 = () => {
return new Promise((resolve, reject) => {
window.addEventListener("load", async () => {
if (window.ethereum) {
const web3 = new Web3(window.ethereum);
try {
// ask user permission to access his accounts
await window.ethereum.request({ method: "eth_requestAccounts" });
resolve(web3);
} catch (error) {
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
contract Greeting {
string public greeting = "hello";
function sayHello() external view returns (string memory) {
return greeting;
}
contract("Factory", function (/* accounts */) {
it("should assert true", async function () {
await Factory.deployed();
return assert.isTrue(true);
});
describe("#createChild()",async () => {
let factory;
beforeEach(async ()=>{
factory = await Factory.deployed();