Wallogit.com
2017 © Pedro Peláez
NEO blockchain implementation for PHP
, (*1)
PHP SDK for the NEO blockchain. , (*2)
Currently there isn't much documentation besides this Readme. We could use it! Do a PR if you'd like to help us :). Though there are a lot of examples, (*3)
To start using neo-php you need to have composer installed. When you're ready openup a terminal and type in:, (*4)
composer require cityofzion/neo-php @dev
From there on include the autoloader and you can use all of the juicy neo-php features., (*5)
The wallet part of neo-php consists out of initializers that have multiple functions., (*6)
Create new unencrypted wallet, (*7)
$newWallet = new NeoPHP\NeoWallet();
Open an unencrypted wallet, (*8)
$wallet = new NeoPHP\NeoWallet("KzfUdP9MbsuL4Ejo1rTWve4JZfa7m1hc397JGXTHhNqJDAqMxZYu");
Create new encrypted wallet, (*9)
$wallet = new NeoPHP\NeoWallet();
$wallet->encryptWallet("passphrase");
Open an encrypted wallet, (*10)
$wallet = new NeoPHP\NeoWallet("6PYMFa9gMAcBrTaAs8JyDrtoGLqb45P8dnmUfVVNcfLd9xKUdffSNfKWKp","passphrase");
Encrypt an existing wallet, (*11)
$wallet = new NeoPHP\NeoWallet("KzfUdP9MbsuL4Ejo1rTWve4JZfa7m1hc397JGXTHhNqJDAqMxZYu");
$wallet->encryptWallet("passphrase");
BOOL to test if wallet is an encrypted wallet, (*12)
$wallet->isNEP2();
String get the encrypted address, when isNEP2(), (*13)
$wallet->getEncryptedKey();
String get wif for initialized wallet, (*14)
$wallet->getWif();
String get address for initialized wallet, (*15)
$wallet->getAddress();
String get key for initialized wallet, (*16)
$wallet->getPrivateKey()
We're working on NEP5 integration. For now we're able to request the majority of the NEP5 tokens balance with a specified address., (*17)
Requesting NEP-5 Token balance for address, (*18)
$rpcObject = new NeoRPC();
$rpcObject->setNode("https://seed1.redpulse.com:10331");
\NeoPHP\NEP5::getTokenBalance($rpcObject,NeoPHP\NeoAssets::ASSET_ZPT,"AKDVzYGLczmykdtRaejgvWeZrvdkVEvQ1X");
\NeoPHP\NEP5::getTokenBalance($rpcObject,NeoPHP\NeoAssets::ASSET_TKY,"AKDVzYGLczmykdtRaejgvWeZrvdkVEvQ1X")
Right now we have the following "assets" which you can request the balance for:, (*19)
| Token | Asset constant |
|---|---|
| Ontology | NeoPHP\NeoAssets::ASSET_ONT |
| THEKEY | NeoPHP\NeoAssets::ASSET_TKY |
| Congierce token | NeoPHP\NeoAssets::ASSET_CGE |
| Alphacat | NeoPHP\NeoAssets::ASSET_ACAT |
| Narrative Token | NeoPHP\NeoAssets::ASSET_NRVE |
| Red Pulse | NeoPHP\NeoAssets::ASSET_RPX |
| DeepBrainChain | NeoPHP\NeoAssets::ASSET_DBC |
| QLink | NeoPHP\NeoAssets::ASSET_QLC |
| Trinity Network Credit | NeoPHP\NeoAssets::ASSET_TN |
| Zeepin Token | NeoPHP\NeoAssets::ASSET_ZPT |
| PikcioChain | NeoPHP\NeoAssets::ASSET_PKC |
The RPC is the way to talk to the different blockchain nodes. For example: We use it to request the balance for the NEP-5 tokens., (*20)
Connecting to a RPC Node, (*21)
$neo = new NeoRPC(); #use false as argument to go to testnet
//$neo->setNode($neo->getFastestNode());
$neo->setNode("http://seed5.neo.org:10332");
Asking for balance using the CityOfZion API, (*22)
$neo->getBalance($testAddress);
Query the account asset information, according to the account address., (*23)
$neo->getAccountState($testAddress);
Query the asset information, based on the specified asset number., (*24)
$neo->getAssetState($neoAssetID);
Returns the hash of the tallest block in the main chain., (*25)
$neo->getBestBlockHash();
Returns the corresponding block information according to the specified index OR hash., (*26)
$neo->getBlock("0x56adb8cc0de3e4fff7b8641988c83bfca214802d263495403055efdd437234c4");
$neo->getBlock(1533325);
Gets the number of blocks in the main chain., (*27)
$neo->getBlockCount();
Calculate claim transaction amounts in order use sendrawtransaction to make a claim., (*28)
$neo->getBlockSysFee($neo->getBlockCount()-1);
Returns the hash value of the corresponding block, based on the specified index., (*29)
$neo->getBlockHash($neo->getBlockCount()-1);
Gets the current number of connections for the node., (*30)
$neo->getConnectionCount();
Query contract information, according to the contract script hash., (*31)
$neo->getContractState("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7");
Obtain the list of unconfirmed transactions in memory., (*32)
$neo->getRawMemPool();
Returns the corresponding transaction information, based on the specified hash value., (*33)
$neo->getRawTransaction("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",true);
Query contract information, according to the contract script hash., (*34)
$neo->getStorage("c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", "74657374");
Returns the corresponding transaction output information (returned change), based on the specified hash and index., (*35)
$neo->getTxOut("0e3c0f477d80acda1c45650b3260e2410287ef78c291f6e02f0214daca2bd2cf",0);
Broadcasts a transaction over the NEO network. There are many kinds of transactions, as specified in the network protocol documentation, (*36)
$transaction_id = ""; //A hexadecimal string that has been serialized, after the signed transaction in the program.
$broadcastTransaction = $neo->sendRawTransaction($transaction_id);
if ($broadcastTransaction)
echo "Sent";
else
echo "Hasn't been sent";
Validate an address, (*37)
if ($neo->validateAddress("AXCLjFvfi47R1sKLrebbRJnqWgbcsncfro"))
echo "Address is valid";
else
echo "Address is not valid";
You can also run the cli-create-wallet-interactive.php example to generate a new wallet. You can do so on a fresh virtual and disconnected Linux distro, you can do a clean run and keep your wallet safe., (*38)
Neo-PHP Features a full CoinMarketCap API integration., (*39)
To initiate the object, (*40)
//setup coinmarketcap object
$cmcObject = new \NeoPHP\CoinMarketCap();
//set currency, if not set it defaults to USD
$cmcObject->setCurrency("EUR");
To request the ticker, (*41)
print_r($cmcObject->getTicker());
Arguments are start and limit. Similar to MySQL start and limit, (*42)
To request the ticker for a specific currency, (*43)
//get ticket for asset GAS print_r($cmcObject->getTickerForAsset(\NeoPHP\Assets\NeoAssets::ASSET_GAS)); //get ticket for asset NEO print_r($cmcObject->getTickerForAsset(\NeoPHP\Assets\NeoAssets::ASSET_NEO));
Check NEP-5 asset constants of this documentation for the right assets, (*44)
To get global data, (*45)
//get global data print_r($cmcObject->getGlobalData());
Check NEP-5 asset constants of this documentation for the right assets, (*46)
Benjamin de Bos (LinkedIn) - Neodius (NEO Blockchain App) & ITSVision, (*47)
Dean van Dugteren (LinkedIn) - NEO dApp Starter Kit, Vidiato, Click.DJ, (*48)
Check out Neodius, (*49)
Licensed under MIT License, (*50)
Enjoy!, (*51)