On Github debris / ethereum.js-presentation
javascript code
web3.eth.coinbase.then(function (result) {
var coinbase = result;
});
json object
{
"jsonrpc" : "2.0",
"method" : "eth_coinbase",
"params" : null,
"id" : 1
}
curl request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_number","params":null,"id":1}' http://localhost:8080
Callback hell
asyncCall(function (result) {
// do something
anotherAsyncCall(function (result2) {
// do something 2
oneMoreAsyncCall(function (err, result3) {
// the third and final async response
if (err) {
//handle any error resulting from any of the above calls
return; // finally!
}
})
})
})
asyncCall()
.then(function(data1){
// do something...
return anotherAsyncCall();
})
.then(function(data2){
// do something...
return oneMoreAsyncCall();
})
.then(function(data3){
// the third and final async response
})
.fail(function(err) {
// handle any error resulting from any of the above calls
})
.done();
web3.eth.coinbase.then(function (result) {
var coinbase = result;
console.log(coinbase); // "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
return web3.eth.balanceAt(coinbase);
}).then(function (result) {
var balance = result;
console.log(balance); // "0x32884442997a37a000"
});
web3.eth.balanceAt(web3.eth.coinbase).then(function (result) {
var balance = result;
console.log(balance); // "0x32884442997a37a000"
});
web3.eth.somemethod(x).then(function (result) {
// some code
});
var x = {
"a" : "text",
"b" : Promise,
"c" : 7,
"d" : Promise
}
var x = {
"a" : "text",
"b" : "Hello World!",
"c" : 7,
"d" : ["Hello", "World", Promise]
}
var x = {
"a" : "text",
"b" : "Hello World!",
"c" : 7,
"d" : ["Hello", "World", 14]
}
var source = "" +
"contract test {" +
" function multiply(uint a) returns(uint d) {" +
" return a * 7;" +
" }" +
"}";
// create contract
web3.eth.transact({code: web3.eth.solidity(source)}).then(function (address) {
// ...
});
var desc = [{
"name": "multiply",
"inputs": [{
"name": "a",
"type": "uint256"
}],
"outputs": [{
"name": "d",
"type": "uint256"
}]
}];
// create description
var account = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"; //
var contract = web3.contract(account, desc); // create contract object here!
contract.multiply(1).call().then(function(res) {
var result = res[0];
console.log(result); // 7
});