Skip to content

Instantly share code, notes, and snippets.

View sagar-barapatre's full-sized avatar
💬
Enjoying the journey ...!!

Sagar Barapatre sagar-barapatre

💬
Enjoying the journey ...!!
View GitHub Profile
@sagar-barapatre
sagar-barapatre / getWeb3.js
Last active April 26, 2022 05:48
Web3.js Boilerplate code
import NFTContractBuild from 'contracts/NFT.json';
import Web3 from 'web3';
let selectedAccount;
let isInitialized = false;
let nftContract;
let provider = window.ethereum;
// sample init function. This runs everytime we need to connect to blockchain.
const init = async () => {
@sagar-barapatre
sagar-barapatre / jwt.js
Created April 5, 2022 04:15
Implementation of JWT in Node.js
const express = require('express');
const jwt = require('jsonwebtoken');
const app = express();
app.get('/api',(req,res) =>{
res.json({
message:'Welcome to the API'
})
})
@sagar-barapatre
sagar-barapatre / app.js
Last active November 3, 2022 13:37
Authenticate using Passport.js
const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true,
},
username: {
@sagar-barapatre
sagar-barapatre / app.js
Created April 4, 2022 17:03
Setup a Nodejs Backend
const express = require("express");
const app = express();
require("dotenv").config();
const mongoose = require("mongoose");
const user = require("./models/user");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
mongoose.connect(process.env.MONGODB_URI, {
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
@sagar-barapatre
sagar-barapatre / Allowance.sol
Created April 4, 2022 11:08
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol";
contract Allowance is Ownable {
using SafeMath for uint;
event AllowanceChanged(address indexed _forWho, address indexed _byWhom, uint _oldAmount , uint _newAmount);
mapping(address => uint) public allowance;
@sagar-barapatre
sagar-barapatre / SmartContract.sol
Created April 4, 2022 11:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
pragma solidity ^0.6.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol";
import "./Allowance.sol";
contract SharedWallet is Ownable, Allowance {
event MoneySent(address indexed _beneficiary, uint _amount);
event MoneyReceived(address indexed _from, uint _amount);