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 / ballot.sol
Created July 22, 2018 21:33
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.4.24+commit.e67f0147.js&optimize=true&gist=
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
@mayorcoded
mayorcoded / proof.sol
Created July 22, 2018 21:35
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.4.24+commit.e67f0147.js&optimize=true&gist=
pragma solidity ^0.4.23;
contract OwnershipProof{
//FileDetails structure
struct FileDetails {
uint256 timestamp;
string owner;
}
@mayorcoded
mayorcoded / OwnershipProof.sol
Created July 22, 2018 21:36
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.4.24+commit.e67f0147.js&optimize=true&gist=
pragma solidity ^0.4.23;
contract OwnershipProof{
//FileDetails structure
struct FileDetails {
uint256 timestamp;
string owner;
}
@mayorcoded
mayorcoded / FoodCart.js
Last active October 30, 2018 03:26
This is the FoodCart smart contract for the article: Debugging smart contracts with Truffle Debugger published here (https://www.mayowatudonu.com/blockchain/debugging-smartcontracts-with-truffle-debugger)
pragma solidity ^0.4.24;
contract FoodCart{
/* set owner of contract */
address owner;
/* a variable to track the most recent sku of a food item */
uint8 skuCount;
/* an enum to store food item state */
var FoodCart = artifacts.require("./FoodCart.sol");
module.exports = function(deployer) {
deployer.deploy(FoodCart);
};
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);});}
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
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)> buyFoodItemFromCart(0, 10);
truffle(develop)> { name: 'Fried Rice', sku: 0, price: 10, state: 'Sold', foodItemExist: false }
truffle(develop)> buyFoodItemFromCart(6, 10);
truffle(develop)> UnhandledPromiseRejectionWarning: Error: VM Exception while processing transaction: revert ...