Skip to content

Instantly share code, notes, and snippets.

@MichalZalecki MichalZalecki/accountstate Secret
Last active Jun 2, 2018

Embed
What would you like to do?
Intro to Nebulas for Ethereum Smart Contract Developers
curl -X POST \
http://localhost:8685/v1/user/accountstate \
-H 'content-type: application/json' \
-d '{ "address": "n1Vg9Ngvi3vXo5f59diW4MK8XXger36weUm" }'
{"result":{"balance":"1000000000000000000","nonce":"0","type":87}}
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"
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"
}
}
uint max = 2**256 - 1; // 115792089237316195423570985008687907853269984665640564039457584007913129639935
max + 1; // 0
class Ownable {
constructor() {
LocalContractStorage.defineProperty(this, "storage");
}
init() {
this.owner = Blockchain.transaction.from;
}
}
contract Ownable {
address owner;
constructor() public {
owner = msg.owner;
}
}
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
using SafeMath for uint256;
uint max = 2**256 - 1;
max.add(1); // VM error
class StandardToken {
init() {
// ...
}
}
module.exports = StandardToken;
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 {
// ...
}
}
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");
}
// ...
}
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": ""
}
}
Blockchain.transfer(address, value);
address(address).transfer(value);
Blockchain.transaction.from // sender address (string)
Blockchain.transaction.value // number of Wei sent (string)
Blockchain.block.timestamp // current block timestamp (number)
msg.sender // sender address (address)
msg.value // number of Wei sent (uint256)
block.timestamp // current block timestamp (uint256)
Blockchain.verifyAddress(address);
class Visibility {
function visible() {
this._hidden();
}
function _hidden() {}
}
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
You can’t perform that action at this time.