This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.17; | |
| contract NumberStorage { | |
| uint public storedNumber; | |
| // Storing function | |
| function setNumber(uint _number) public { | |
| storedNumber = _number; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function main (){ | |
| const NumberStorage = await ethers.getContractFactory("NumberStorage"); // instance of contract | |
| const numberStorage = await NumberStorage.deploy(); // deploy contract | |
| console.log("NumberStorage deployed to:", numberStorage.address); | |
| } | |
| main() | |
| .then(() => process.exit(0)) | |
| .catch(error => { | |
| console.error(error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const {expect} = require("chai"); | |
| describe("NumberStorage Smart Contract", function(){ | |
| it("Should set the value of storedNumber value to the value passed in", async function(){ | |
| const NumberStorage = await ethers.getContractFactory("NumberStorage"); | |
| const numberStorage = await NumberStorage.deploy(); | |
| await numberStorage.setNumber(21) | |
| console.log(await numberStorage.storedNumber()) | |
| expect(await numberStorage.storedNumber()).to.equal(21) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** @type import(‘hardhat/config’).HardhatUserConfig */ | |
| require("@nomiclabs/hardhat-waffle") | |
| require("dotenv").config() | |
| module.exports = { | |
| solidity: "0.8.17", | |
| networks: { | |
| goerli: { | |
| url: process.env.GOERLI_URL, | |
| accounts: [process.env.PRIVATE_KEY] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use solana_program::{ | |
| account_info::{next_account_info, AccountInfo}, | |
| entrypoint, | |
| entrypoint::ProgramResult, | |
| msg, | |
| pubkey::Pubkey, | |
| }; | |
| // Declare and export the program's entrypoint | |
| entrypoint!(process_instruction); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const transaction = new web3.Transaction(); | |
| transaction.add( | |
| new web3.TransactionInstruction({ | |
| keys: [], | |
| programId: new web3.PublicKey(pg.PROGRAM_ID), | |
| }), | |
| ); | |
| console.log("Forwarding Transaction"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var NumberStorage = artifacts.require("NumberStorage"); | |
| module.exports = function(deployer) { | |
| deployer.deploy(NumberStorage); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Web3 = require('web3') | |
| const web3 = new Web3("http://10.0.2.15:8545") | |
| const contractAddress = 'XXXXXXXXXXXXXXXXXXX' | |
| const abi = [{"inputs":[],"name":"getNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_number","type":"uint256"}],"name":"setNumber","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"storedNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] | |
| const NumberStorage = new web3.eth.Contract(abi, contractAddress); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Import required modules and components | |
| import './App.css'; // Importing the App.css file for styling | |
| import { useState, useEffect } from "react"; // Importing the useState and useEffect hooks from React | |
| import { ethers } from "ethers"; // Importing ethers library for interacting with Ethereum | |
| import Fetch from "./components/Fetch"; // Importing the Fetch component | |
| import Store from "./components/Store"; // Importing the Store component | |
| function App() { | |
| // Set initial state using the useState hook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from "react"; | |
| // This is a functional component named 'Fetch' that receives the 'state' object as a prop. | |
| const Fetch = ({ state }) => { | |
| // The 'contract' object is destructured from the 'state' object. | |
| const { contract } = state; | |
| // This creates a new state variable named 'storedNumber' and a function named 'setStoredNumber' to update it | |
| const [storedNumber, setStoredNumber] = useState("Not Available"); |
OlderNewer