Skip to content

Instantly share code, notes, and snippets.

@nodlAndHodl
nodlAndHodl / contracts...Functions.sol
Last active February 4, 2022 05:29
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.11+commit.d7f03943.js&optimize=false&runs=200&gist=
pragma solidity >=0.8.10;
contract FunctionsContract {
string ownerName;
uint8 ownerAge;
// Constructor
constructor (string memory name, uint8 age) public {
ownerName = name;
@nodlAndHodl
nodlAndHodl / contracts...GlobalVariables.sol
Created February 4, 2022 05:01
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=false&runs=200&gist=
pragma solidity >=0.4.24;
contract GlobalVariables {
string public lastCaller = "not-set";
// Demonstrates the use of the ether subdenominations
function etherUnitsTest() public pure returns(bool) {
// True
bool value = (1 ether == 1000 finney);
@nodlAndHodl
nodlAndHodl / contracts...StringConversion.sol
Created February 4, 2022 04:59
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=
pragma solidity >=0.4.22 <0.9.0;
contract StringConversion {
function getStringElementAtIndex(uint index, string memory myString) public pure returns (byte){
bytes memory stringToBytes = bytes(myString);
return stringToBytes[index];
}
}

Solidity Notes

Solidity has basic structure like so

Contracts

contract NewContract {
  uint data; // contract fields like this are in storage
  
constructor(uint _data) public {
const Web3 = require('web3');
const url = 'http://localhost:8545'; //ganache-cli rpc
let web3 = new Web3(new Web3.providers.HttpProvider(url));
const EthereumTx = require('ethereumjs-tx').Transaction
web3.eth.getAccounts().then(accounts => {
//sending eth using the sendTransaction.
web3.eth.personal.sendTransaction({
from: accounts[1],
gasPrice: "20000000000",

Keybase proof

I hereby claim:

  • I am shoupn on github.
  • I am shoupnb (https://keybase.io/shoupnb) on keybase.
  • I have a public key ASAiObVY54dctYeU9xb7N7dkdudB39A5yNsHHT0yfQjZ5Ao

To claim this, I am signing this object:

@nodlAndHodl
nodlAndHodl / EthChatter.sol
Created December 16, 2020 17:53
EthChatter.sol
pragma solidity ^0.5.0;
contract EthChatter {
struct Message{
address sender;
bytes32 message;
bool encrypted;
}
using System;
using System.Collections.Generic;
namespace OpenClosedPrincipleExample
{
class Program
{
static void Main(string[] args)
{
var customerMessages = new List<Message>
class GenericClass<T> where T : class
{
private T _genericField;
public T genericProperty { get; set; }
public GenericClass(T value)
{
_genericField = value;
}
class GenericClass<T> where T
{
private T _genericField;
public T genericProperty { get; set; }
public GenericClass(T value)
{
_genericField = value;
}