Skip to content

Instantly share code, notes, and snippets.

View mayorcoded's full-sized avatar
🎯
Focusing

Mayowa Tudonu mayorcoded

🎯
Focusing
View GitHub Profile
@mayorcoded
mayorcoded / Membershi.sol
Last active May 12, 2023 21:57
This gist creates a membership card for new members, and distributes reward to each new member.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Membership {
uint256 public totalAmount;
uint8 public constant EARLY_MEMBER = 10;
uint8 public constant PRO_MEMBER = 20;
@mayorcoded
mayorcoded / gist-ae67b8b9425f62abb1a47f092945a386...AMM-demo.sol
Created August 27, 2022 09:11
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.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
contract AMM {
}
Some solidity
require('dotenv').config();
const mongodbUri = require('mongodb-uri');
const {MongoClient} = require('mongodb');
async function runMigration(){
const uri = process.env.DATABASE_URL;
const uriObject = mongodbUri.parse(uri);
const client = new MongoClient(uri,{ useNewUrlParser: true, useUnifiedTopology: true });
try {
await client.connect();
truffle(develop)> buyFoodItemFromCart(6, 10);
truffle(develop)> UnhandledPromiseRejectionWarning: Error: VM Exception while processing transaction: revert ...
truffle(develop)> buyFoodItemFromCart(0, 10);
truffle(develop)> { name: 'Fried Rice', sku: 0, price: 10, state: 'Sold', foodItemExist: false }
let buyFoodItemFromCart = (itemSku, amount) => {foodCart.buyFoodItem(itemSku, {from: buyerAddress, value: amount}).then((trxn) => { const details = trxn.logs[0].args; details.sku = details.sku.toNumber(); details.price = details.price.toNumber(); details.state = trxn.logs[0].event; console.log(details);});}
truffle(develop)> addFoodItemToCart('Fried Rice', 10);
truffle(develop)> { name: 'Fried Rice',sku: 0, price: 10, state: 'ForSale', foodItemExist: true } //output
truffle(develop)> addFoodItemToCart('Chicken Pepper Soup', 10);
truffle(develop)> { name: 'Chicken Pepper Soup', sku: 1, price: 10, state: 'ForSale', foodItemExist: true } //output
truffle(develop)> addFoodItemToCart('Pepperoni Pizza', 50);
truffle(develop)> { name: 'Pepperoni Pizza', sku: 2, price: 50, state: 'ForSale', foodItemExist: true } //output
truffle(develop)> let addFoodItemToCart = (foodName, price) => {foodCart.addFoodItem(foodName, price).then((trxn) => { const details = trxn.logs[0].args; details.sku = details.sku.toNumber(); details.price = details.price.toNumber(); details.state = trxn.logs[0].event; console.log(details);});}
var FoodCart = artifacts.require("./FoodCart.sol");
module.exports = function(deployer) {
deployer.deploy(FoodCart);
};