Skip to content

Instantly share code, notes, and snippets.

View bonedaddy's full-sized avatar
🌷
pfSense > cisco

bonedaddy bonedaddy

🌷
pfSense > cisco
  • Canada
View GitHub Profile

Answers to Deep Questions about Solidity

The following list of questions was taken from https://www.reddit.com/r/ethereum/comments/72reba/do_you_have_deep_questions_about_solidity_or_the/

An updated summary on the different ways one could have two contracts interact (DELEGATECALL, STATICCALL, libraries, all that stuff) with clear pros/cons for each (gas cost, whether it requires EVM assembly directives, etc)

Question by /u/drcode

I won't talk about low-level opcodes here because of the brevity of the answer. In general, there are four ways functions can be called in Solidity:

def __init__(self, dataStoreContractAddress, contractAbiFile):
with open(contractAbiFile, 'r') as abi_definition:
self.abi = json.load(abi_definition)
self.dataStoreContractAddress = dataStoreContractAddress
self.w3 = Web3(IPCProvider('/home/a/.ethereum/geth.ipc'))
self.w3_contract = self.w3.eth.contract(self.abi, self.dataStoreContractAddress)
pragma solidity 0.4.18;
// implement safemath as a library
library SafeMath {
// We use `pure` bbecause it promises that the value for the function depends ONLY
// on the function arguments
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
require(a == 0 || c / a == b);

To generate random numbers for your contract you must provide the contract with the following interface

interface RandomNumberGeneratorInterface 
    function getRandomNumber(uint256 _max) public returns (uint256);
}

Example of how you would use it with a contract

pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract YoutubeViews is usingOraclize {
uint256 public ethUSD;
mapping (bytes32 => bool) public validOraclizeIds;
event newOraclizeQuery(string description);
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract lol is usingOraclize {
uint public DieselPriceUSD;
event newOraclizeQuery(string description);
event newDieselPrice(string price);
pragma solidity 0.4.19;
import "./Modules/Oraclize.sol";
contract test is usingOraclize {
uint256 public ethUSD;
pragma solidity 0.4.19;
import "./Modules/Oraclize.sol";
contract test is usingOraclize {
uint256 public ethUSD;
pragma solidity 0.4.19;
import "./Modules/Oraclize.sol";
contract test is usingOraclize {
uint256 public ethUSD;
package main
import (
"fmt"
//"strings"
"net/http"
"io/ioutil"
"log"
"encoding/json"
)