Skip to content

Instantly share code, notes, and snippets.

@denispeplin
Last active December 10, 2017 06:53
Show Gist options
  • Save denispeplin/0a8a4c44a93d12087b972b2a083713c8 to your computer and use it in GitHub Desktop.
Save denispeplin/0a8a4c44a93d12087b972b2a083713c8 to your computer and use it in GitHub Desktop.
Source code to Etherscan

Got code here: https://www.ethereum.org/greeter

Got some info from this page: https://ethereum.stackexchange.com/questions/3256/how-do-i-find-out-the-solidity-compiler-version-i-am-using

Comments removed, constructor removed.

Published here: https://rinkeby.etherscan.io/verifyContract?a=0x03aafff2181174ac8d9ebc6a0c2c3efbb58548dc

With comments, same result, no problems.

With constructor:

Hello World! for constructor will be transformed to 0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c48656c6c6f20576f726c64210000000000000000000000000000000000000000 using etherium-abi: https://ethereum.stackexchange.com/a/22902/21182 (see index.js in this gist).

With properly encoded ABI params, contract with constructor also works.

pragma solidity ^0.4.18;
contract mortal {
address owner;
function mortal() public { owner = msg.sender; }
function kill() public { if (msg.sender == owner) selfdestruct(owner); }
}
contract greeter is mortal {
string greeting = "Hello World!";
function greet() public constant returns (string) {
return greeting;
}
}
pragma solidity ^0.4.18;
contract mortal {
/* Define variable owner of the type address */
address owner;
/* This function is executed at initialization and sets the owner of the contract */
function mortal() public { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() public { if (msg.sender == owner) selfdestruct(owner); }
}
contract greeter is mortal {
/* Define variable greeting of the type string */
string greeting = "Hello World!";
/* Main function */
function greet() public constant returns (string) {
return greeting;
}
}
pragma solidity ^0.4.18;
contract mortal {
/* Define variable owner of the type address */
address owner;
/* This function is executed at initialization and sets the owner of the contract */
function mortal() public { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() public { if (msg.sender == owner) selfdestruct(owner); }
}
contract greeter is mortal {
/* Define variable greeting of the type string */
string greeting;
/* This runs when the contract is executed */
function greeter(string _greeting) public {
greeting = _greeting;
}
/* Main function */
function greet() public constant returns (string) {
return greeting;
}
}
// npm install
// node index.js
var abi = require('ethereumjs-abi')
var parameterTypes = ["string"];
var parameterValues = ["Hello World!"];
var encoded = abi.rawEncode(parameterTypes, parameterValues);
console.log(encoded.toString('hex'));
{
"name": "greeter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "https://gist.github.com/denispeplin/0a8a4c44a93d12087b972b2a083713c8/edit",
"dependencies": {
"ethereumjs-abi": "^0.6.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment