-
-
Save MichalZalecki/fc88bd132654e172c882369b14bdedb6 to your computer and use it in GitHub Desktop.
Intro to Nebulas for Ethereum Smart Contract Developers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
http://localhost:8685/v1/user/accountstate \ | |
-H 'content-type: application/json' \ | |
-d '{ "address": "n1Vg9Ngvi3vXo5f59diW4MK8XXger36weUm" }' | |
{"result":{"balance":"1000000000000000000","nonce":"0","type":87}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BigNumber = require("bignumber.js"); | |
Number.MAX_SAFE_INTEGER; // 9007199254740991 | |
Number.MAX_SAFE_INTEGER + 1; // 9007199254740992 | |
Number.MAX_SAFE_INTEGER + 2; // 9007199254740992 | |
const number = new BigNumber(Number.MAX_SAFE_INTEGER); | |
number.plus(2).toString(); // "9007199254740993" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
http://localhost:8685/v1/user/call \ | |
-H 'content-type: application/json' \ | |
-d '{ | |
"from": "n1QA4usgq7sJbcM5LEkJWpgyNBcKtVEULFf", | |
"to": "n1mQoB6HneRuu7c15Sy79CPHv8rhkNQinJe", | |
"value": "0", | |
"gasPrice": "1000000", | |
"gasLimit": "2000000", | |
"contract": { "function": "myView", "args": "[100]" } | |
} | |
' | |
{ | |
"result": { | |
"result": "{\"key\":\"value\"}", | |
"execute_err": "", | |
"estimate_gas": "20126" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint max = 2**256 - 1; // 115792089237316195423570985008687907853269984665640564039457584007913129639935 | |
max + 1; // 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ownable { | |
constructor() { | |
LocalContractStorage.defineProperty(this, "storage"); | |
} | |
init() { | |
this.owner = Blockchain.transaction.from; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Ownable { | |
address owner; | |
constructor() public { | |
owner = msg.owner; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol"; | |
using SafeMath for uint256; | |
uint max = 2**256 - 1; | |
max.add(1); // VM error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StandardToken { | |
init() { | |
// ... | |
} | |
} | |
module.exports = StandardToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Crowdsale is MintedCrowdsale, CappedCrowdsale { | |
constructor(uint256 _rate, address _wallet, ERC20 _token) public { | |
// ... | |
} | |
function () public payable { | |
buyTokens(msg.sender); | |
} | |
function buyTokens(address _beneficiary) public payable { | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.4.24; | |
import "truffle/Assert.sol"; | |
import "../contracts/Ownable.sol"; | |
contract OwnableTest { | |
Ownable ownable; | |
function beforeEach() public { | |
ownable = new Ownable(); | |
} | |
function testConstructor() public { | |
Assert.equal(ownable.owner(), address(this), "owner address is invalid"); | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
http://localhost:8685/v1/admin/transactionWithPassphrase \ | |
-H 'content-type: application/json' \ | |
-d '{ | |
"transaction": { | |
"from": "n1Vg9Ngvi3vXo5f59diW4MK8XXger36weUm", | |
"to": "n1gQgDb72yL1vrRcUEP3219ytcZGxEmcc9u", | |
"value": "0", | |
"nonce": 59, | |
"gasPrice": "1000000", | |
"gasLimit": "2000000", | |
"contract": { "function": "myMethod", "args": "" } | |
}, | |
"passphrase": "passphrase" | |
} | |
' | |
{ | |
"result": { | |
"txhash": "36a61c6413e71387f34b0b442e73d2a8b54646917c58338166b0473292c0b26d", | |
"contract_address": "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blockchain.transfer(address, value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
address(address).transfer(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blockchain.transaction.from // sender address (string) | |
Blockchain.transaction.value // number of Wei sent (string) | |
Blockchain.block.timestamp // current block timestamp (number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msg.sender // sender address (address) | |
msg.value // number of Wei sent (uint256) | |
block.timestamp // current block timestamp (uint256) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blockchain.verifyAddress(address); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Visibility { | |
function visible() { | |
this._hidden(); | |
} | |
function _hidden() {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Visibility { | |
function visible() pure public {} | |
function hiddenFromOthers() pure private {} | |
function visibleOnlyForFunctions() pure external {} | |
function visibleForChildContracts() pure internal {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment