PHP code example of cityofzion / neo-php

1. Go to this page and download the library: Download cityofzion/neo-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cityofzion / neo-php example snippets


$newWallet = new NeoPHP\NeoWallet();

$wallet = new NeoPHP\NeoWallet("KzfUdP9MbsuL4Ejo1rTWve4JZfa7m1hc397JGXTHhNqJDAqMxZYu");

$wallet = new NeoPHP\NeoWallet();
$wallet->encryptWallet("passphrase");

$wallet = new NeoPHP\NeoWallet("6PYMFa9gMAcBrTaAs8JyDrtoGLqb45P8dnmUfVVNcfLd9xKUdffSNfKWKp","passphrase");

$wallet = new NeoPHP\NeoWallet("KzfUdP9MbsuL4Ejo1rTWve4JZfa7m1hc397JGXTHhNqJDAqMxZYu");
$wallet->encryptWallet("passphrase");

$wallet->isNEP2();

$wallet->getEncryptedKey();

$wallet->getWif();

$wallet->getAddress();

$wallet->getPrivateKey()

$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")

$neo = new NeoRPC(); #use false as argument to go to testnet
//$neo->setNode($neo->getFastestNode());
$neo->setNode("http://seed5.neo.org:10332");

$neo->getBalance($testAddress);

$neo->getAccountState($testAddress);

$neo->getAssetState($neoAssetID);

$neo->getBestBlockHash();

$neo->getBlock("0x56adb8cc0de3e4fff7b8641988c83bfca214802d263495403055efdd437234c4");
$neo->getBlock(1533325);

$neo->getBlockCount();

$neo->getBlockSysFee($neo->getBlockCount()-1);

$neo->getBlockHash($neo->getBlockCount()-1);

$neo->getConnectionCount();

$neo->getContractState("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7");

$neo->getRawMemPool();

$neo->getRawTransaction("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",true);

$neo->getStorage("c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", "74657374");

$neo->getTxOut("0e3c0f477d80acda1c45650b3260e2410287ef78c291f6e02f0214daca2bd2cf",0);

$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";

if ($neo->validateAddress("AXCLjFvfi47R1sKLrebbRJnqWgbcsncfro"))
	echo "Address is valid";
else
	echo "Address is not valid";

//setup coinmarketcap object
$cmcObject = new \NeoPHP\CoinMarketCap();

//set currency, if not set it defaults to USD
$cmcObject->setCurrency("EUR");

print_r($cmcObject->getTicker());

//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));

//get global data
print_r($cmcObject->getGlobalData());

composer