Skip to content

Instantly share code, notes, and snippets.

@web3author
web3author / Store.js
Last active March 19, 2023 08:49
components/Store.js script to set stored number from blockchain by calling Smart Contract
// Define a functional component named 'Store' that takes a single prop named 'state'
const Store = ({ state }) => {
// Define an async function named 'storeNum' that takes an 'event' object as its parameter.
const storeNum = async (event) => {
// Prevent the default form submission behavior.
event.preventDefault();
// Retrieve the contract object from the 'state' prop.
@web3author
web3author / NumberStorage.vy
Created March 18, 2023 08:02
Hello world Smart Contract NumberStorage.vy written in Vyper
# SPDX-License-Identifier: UNLICENSED
# @version ^0.3.7
storedNumber: public(uint256)
# Storing function
@external
def setNumber(_number: uint256):
self.storedNumber = _number
@web3author
web3author / deploy.py
Created March 18, 2023 08:03
Brownie based deployment file for Vyper Smart Contract
#!/usr/bin/python3
from brownie import NumberStorage, accounts
def main():
return NumberStorage.deploy({'from': accounts[0]})
@web3author
web3author / interact.py
Created March 18, 2023 08:04
web3.py script to interact with a deployed Smart Contract using address and ABI
from web3 import Web3
import codecs
# Connect to a Web3 provider
w3 = Web3(Web3.HTTPProvider('http://10.0.2.15:8545'))
# Address of the smart contract
contract_address = "0x4235d917d3420BF5adf03aE5146701B87D179752"
# ABI of the smart contract
@web3author
web3author / server.html
Last active March 18, 2023 08:07
HTML template file for Django application (Server side interaction)
<html>
<head>
<title>numberStore - Server Side</title>
<script src="https://cdn.jsdelivr.net/npm/web3@1.5.2/dist/web3.min.js"></script>
<script>
// Connect to MetaMask on page load
window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
@web3author
web3author / client.html
Created March 18, 2023 08:07
HTML template file for Django application (Client side interaction)
<html>
<head>
<title>numberStore - Client Side</title>
<script src="https://cdn.jsdelivr.net/npm/web3@1.5.2/dist/web3.min.js"></script>
<script>
const abi = [{"stateMutability": "nonpayable", "type": "function", "name": "setNumber", "inputs": [{"name": "_number", "type": "uint256"}], "outputs": []}, {"stateMutability": "nonpayable", "type": "function", "name": "getNumber", "inputs": [], "outputs": [{"name": "", "type": "uint256"}]}, {"stateMutability": "view", "type": "function", "name": "storedNumber", "inputs": [], "outputs": [{"name": "", "type": "uint256"}]}];
const address = '0x4235d917d3420BF5adf03aE5146701B87D179752';
// Connect to MetaMask on page load
@web3author
web3author / views.py
Last active March 23, 2023 10:26
Django webapp view file
# Import required libraries
from django.http import HttpResponse
from django.shortcuts import render
from web3 import Web3
# Initialize web3 connection
web3 = Web3(Web3.HTTPProvider('http://10.0.2.15:8545'))
# Define contract address and ABI (Application Binary Interface)
contract_address = '0x4235d917d3420BF5adf03aE5146701B87D179752'
@web3author
web3author / ethereum-rpc-api-calls.json
Created August 4, 2023 11:07
HTTP RPC calls collection for Thunder Client VS Code extension
{
"client": "Thunder Client",
"collectionName": "blockchain-interaction-commands",
"dateExported": "2023-08-04T07:57:26.934Z",
"version": "1.1",
"folders": [],
"requests": [
{
"_id": "b395a4c2-2365-4a5e-ab7b-eebe61ff918f",
"colId": "6ffd056b-4a07-42ed-894b-b8a43a517039",
@web3author
web3author / sum.asm
Created August 24, 2023 12:36
Program to calculate sum of two numbers
; Program to calculate sum of two numbers
; Finally, sum will be stored in register A
; Load first value in register A
MOV A, 10
; Load second value in register B
MOV B, 10
; Add contents of registers A and B, store result in A
@web3author
web3author / compare.asm
Created August 24, 2023 12:38
Program to compare two numbers and find the greater number
; Program to compare two numbers and find the greater number
; Finally, greater number will be stored in register A
; Load first value in register A
MOV A, 47
; Load second value in register B
MOV B, 32
; Compare the values in registers A and B