Update code styling in README

This commit is contained in:
Anton Komarev 2018-02-25 15:34:02 +03:00 committed by GitHub
parent d02fb14bd3
commit 3d134fba8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,14 +30,14 @@ Or you can add this line in composer.json
# Usage # Usage
### New instance ### New instance
``` ```php
use Web3\Web3; use Web3\Web3;
$web3 = new Web3('http://localhost:8545'); $web3 = new Web3('http://localhost:8545');
``` ```
### Using provider ### Using provider
``` ```php
use Web3\Web3; use Web3\Web3;
use Web3\Providers\HttpProvider; use Web3\Providers\HttpProvider;
use Web3\RequestManagers\HttpRequestManager; use Web3\RequestManagers\HttpRequestManager;
@ -49,7 +49,7 @@ $web3 = new Web3(new HttpProvider(new HttpRequestManager('http://localhost:8545'
``` ```
### You can use callback to each rpc call: ### You can use callback to each rpc call:
``` ```php
$web3->clientVersion(function ($err, $version) { $web3->clientVersion(function ($err, $version) {
if ($err !== null) { if ($err !== null) {
// do something // do something
@ -62,7 +62,7 @@ $web3->clientVersion(function ($err, $version) {
``` ```
### Eth ### Eth
``` ```php
use Web3\Web3; use Web3\Web3;
$web3 = new Web3('http://localhost:8545'); $web3 = new Web3('http://localhost:8545');
@ -71,14 +71,14 @@ $eth = $web3->eth;
Or Or
``` ```php
use Web3\Eth; use Web3\Eth;
$eth = new Eth('http://localhost:8545'); $eth = new Eth('http://localhost:8545');
``` ```
### Net ### Net
``` ```php
use Web3\Web3; use Web3\Web3;
$web3 = new Web3('http://localhost:8545'); $web3 = new Web3('http://localhost:8545');
@ -87,7 +87,7 @@ $net = $web3->net;
Or Or
``` ```php
use Web3\Net; use Web3\Net;
$net = new Net('http://localhost:8545'); $net = new Net('http://localhost:8545');
@ -96,7 +96,7 @@ $net = new Net('http://localhost:8545');
### Batch ### Batch
web3 web3
``` ```php
$web3->batch(true); $web3->batch(true);
$web3->clientVersion(); $web3->clientVersion();
$web3->hash('0x1234'); $web3->hash('0x1234');
@ -114,7 +114,7 @@ $web3->execute(function ($err, $data) {
eth eth
``` ```php
$eth->batch(true); $eth->batch(true);
$eth->protocolVersion(); $eth->protocolVersion();
$eth->syncing(); $eth->syncing();
@ -129,7 +129,7 @@ $eth->provider->execute(function ($err, $data) {
``` ```
net net
``` ```php
$net->batch(true); $net->batch(true);
$net->version(); $net->version();
$net->listening(); $net->listening();
@ -144,7 +144,7 @@ $net->provider->execute(function ($err, $data) {
``` ```
personal personal
``` ```php
$personal->batch(true); $personal->batch(true);
$personal->listAccounts(); $personal->listAccounts();
$personal->newAccount('123456'); $personal->newAccount('123456');
@ -160,7 +160,7 @@ $personal->provider->execute(function ($err, $data) {
### Contract ### Contract
``` ```php
use Web3\Contract; use Web3\Contract;
$contract = new Contract('http://localhost:8545', $abi); $contract = new Contract('http://localhost:8545', $abi);
@ -185,14 +185,13 @@ $constructorData = $contract->bytecode($bytecode)->getData($params);
// get function data // get function data
$functionData = $contract->at($contractAddress)->getData($functionName, $params); $functionData = $contract->at($contractAddress)->getData($functionName, $params);
``` ```
# Assign value to outside scope(from callback scope to outside scope) # Assign value to outside scope(from callback scope to outside scope)
Due to callback is not like javascript callback, Due to callback is not like javascript callback,
if we need to assign value to outside scope, if we need to assign value to outside scope,
we need to assign reference to callback. we need to assign reference to callback.
``` ```php
$newAccount = ''; $newAccount = '';
$web3->personal->newAccount('123456', function ($err, $account) use (&$newAccount) { $web3->personal->newAccount('123456', function ($err, $account) use (&$newAccount) {