Giter Club home page Giter Club logo

neo-php's Introduction

neo-php

PHP SDK for the NEO blockchain.

Overview

What does it currently do

  • Installation though Composer
  • Open, create and encrypt unencrypted wallets
  • Create and open encrypted wallet
  • Minimal NEP-5 interation (token balance requesting and Smart Contract parameter factory)
  • All RPC functions are integrated.
  • Address validation
  • It contains a cold wallet generator
  • Coinmarketcap API integration

What will (should) it do

  • Do wallet transactions for: NEO, GAS and NEP-5 Tokens
  • Build, deploy, and run smart contracts
  • A lot more

Documentation

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

Get help or give help

  • Open a new issue if you encounter a problem.
  • Or ping @Deanpress or @Woodehh on the NEO Discord.
  • Pull requests welcome. You can help with wallet functionality, writing tests or documentation, or on any other feature you deem awesome.

Getting started

To start using neo-php you need to have composer installed. When you're ready openup a terminal and type in:

composer require cityofzion/neo-php @dev

From there on include the autoloader and you can use all of the juicy neo-php features.

Wallet functionality:

The wallet part of neo-php consists out of initializers that have multiple functions.

Create new unencrypted wallet

$newWallet = new NeoPHP\NeoWallet();

Open an unencrypted wallet

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

Create new encrypted wallet

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

Open an encrypted wallet

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

Encrypt an existing wallet

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

BOOL to test if wallet is an encrypted wallet

$wallet->isNEP2();

String get the encrypted address, when isNEP2()

$wallet->getEncryptedKey();

String get wif for initialized wallet

$wallet->getWif();

String get address for initialized wallet

$wallet->getAddress();

String get key for initialized wallet

$wallet->getPrivateKey()

Minimal NEP-5 integration

We're working on NEP5 integration. For now we're able to request the majority of the NEP5 tokens balance with a specified address.

Requesting NEP-5 Token balance for address

$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:

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

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.

Connecting to a RPC Node

$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

$neo->getBalance($testAddress);

Query the account asset information, according to the account address.

$neo->getAccountState($testAddress);

Query the asset information, based on the specified asset number.

$neo->getAssetState($neoAssetID);

Returns the hash of the tallest block in the main chain.

$neo->getBestBlockHash();

Returns the corresponding block information according to the specified index OR hash.

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

Gets the number of blocks in the main chain.

$neo->getBlockCount();

Calculate claim transaction amounts in order use sendrawtransaction to make a claim.

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

Returns the hash value of the corresponding block, based on the specified index.

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

Gets the current number of connections for the node.

$neo->getConnectionCount();

Query contract information, according to the contract script hash.

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

Obtain the list of unconfirmed transactions in memory.

$neo->getRawMemPool();

Returns the corresponding transaction information, based on the specified hash value.

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

Query contract information, according to the contract script hash.

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

Returns the corresponding transaction output information (returned change), based on the specified hash and index.

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

Broadcasts a transaction over the NEO network. There are many kinds of transactions, as specified in the network protocol documentation

$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

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

NEO Cold wallet generator

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.

CoinMarketCap integration

Neo-PHP Features a full CoinMarketCap API integration.

To initiate the object

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

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

To request the ticker

print_r($cmcObject->getTicker());

Arguments are start and limit. Similar to MySQL start and limit

To request the ticker for a specific currency

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

To get global data

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

Check NEP-5 asset constants of this documentation for the right assets

Created by

Check out Neodius

Licensed under MIT License

Enjoy!

neo-php's People

Contributors

deanpress avatar owenvoke avatar pepijnolivier avatar woodehh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo-php's Issues

Use versions instead of dev-master

While requiring the package I've noticed that it uses dev-master and writes the version as @dev in composer.json. It will be awesome if you could implement versions for it since without it you can introduce BC changes to the package

Help. transactions.

Hello!
I am working on a project where one of the requirements is:

Transfer NEO or GAS, from one wallet to another wallet!

Is this currently possible with the PHP library? if it is not possible with which library I can execute transactions from one wallet to another using code, I need to automate transactions! that is not necessarily a manual transaction.


With the library for python you can do this type of activities?
On the other hand if they are so kind that they give me some short example to execute a transaction?

Getting an incorrect wallet balance for some tokens

When I request token balances for the following address Aas3fPV8Q3PxUd3WAjXTNYP5tamqsuQy3V, I get back an incorrect balance for these tokens:

  • ONT
  • TNC

How to reproduce:

  • Check balance on NeoScan.io: ~11.45 ONT
  • Request balance via neo-php: 2.8 ONT
require 'vendor/autoload.php';

$rpcObject = new \NeoPHP\NeoRPC();
$node = $rpcObject->getFastestNode();
$rpcObject->setNode($node);
$balance = \NeoPHP\NeoNEP5::getTokenBalance($rpcObject, \NeoPHP\Assets\NeoAssets::ASSET_ONT, 'Aas3fPV8Q3PxUd3WAjXTNYP5tamqsuQy3V');

var_dump($balance);

Can I use this wallet to transfer neo coin from one address to another

I have a neo node installed on my Amazon server. I could connect to it using rpc-functions.php file with $neo->setNode("http://127.0.0.1:10332");

Now I want to know how I will be able to use this library to perform transactions. Can you show a simple example?
Currently, my wallet is empty. Can I use this wallet to transfer neo coin from one address to another?
To perform transactions do we need to start consensus?

I need to invoke the plugin functions from a php class. Is that possible when you are outside namespace? I mean how to import your namespace into my class.

I am new to neo. Please help.

Hardcoded list of assets

NeoPHP\Assets\NeoAssets contains a hardcoded list of all the assets.
In the future, we can expect many more assets on the NEO blockchain.

  1. How did we currently find out about all these assets and their ID ?
  2. Can we query an online service to fetch (and locally cache) all the assets, rather than using a hardcoded list ? (which online service ?)

bcrand() not working

I have looked at your bcrand() function and noticed that it does not work.

You have called openssl_random_pseudo_bytes() as if the arguments were "min, max", but actually they are "length, &output", at least for the current version of PHP.

I have replaced it with mt_rand() and now the function works as expected:

return bcadd(bcmul(bcdiv(mt_rand(), mt_getrandmax(), strlen($max)), bcsub(bcadd($max, 1), $min)), $min);

not running in php

it gives error --> Fatal error: Uncaught Error: Class 'NeoPHP\CoinMarketCap' not found

How convert ByteArray string to NEO address?

Hi, I am doing a getplicationlog and return

array(2) {
    ["type"]=>
    string(9) "ByteArray"
    ["value"]=>
     string(40) "0631901fb121f633fa496d3689649a06628f63c8"
}

Help me, how to convert ByteArray to an address in NEO?

About vin attribute in getRawTransaction

as Example, link to neoscan

NeoPHP Response

array:13 [▼
  "txid" => "0xd1cef7b3e5afc71617f2a9b0203ad5351a678077690ffe626e1bb6ade1d51bcf"
  "size" => 202
  "type" => "ContractTransaction"
  "version" => 0
  "attributes" => []
  "vin" => array:1 [▼
    0 => array:2 [▼
      "txid" => "0x808252f3bf6e4d561c29643c9ebf0181ae40a59219c6b79990a415a335c44e5b"
      "vout" => 0
    ]
  ]
  "vout" => array:1 [▼
    0 => array:4 [▼
      "n" => 0
      "asset" => "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"
      "value" => "200"
      "address" => "AanTXadhgdHzGbmy5ZBPXxR4iPHMivzVPZ"
    ]
  ]
  "sys_fee" => "0"
  "net_fee" => "0"
  "scripts" => array:1 [▶]
  "blockhash" => "0x1173c981404a74d47d6500b9187366eaf3a53d233be517e2ad69d3c2c243d717"
  "confirmations" => 191
  "blocktime" => 1521875926
]

NeoScan API Response

array:21 [▼
  "vouts" => array:1 [▼
    0 => array:4 [▼
      "value" => 200.0
      "n" => 0
      "asset" => "NEO"
      "address" => "AanTXadhgdHzGbmy5ZBPXxR4iPHMivzVPZ"
    ]
  ]
  "vin" => array:1 [▼
    0 => array:5 [▼
      "value" => 200.0
      "txid" => "808252f3bf6e4d561c29643c9ebf0181ae40a59219c6b79990a415a335c44e5b"
      "n" => 0
      "asset" => "NEO"
      "address_hash" => "AHEeAEyCEBj6ev9etuASJS5oa5oZr8gw1L"
    ]
  ]
  "version" => 0
  "type" => "ContractTransaction"
  "txid" => "d1cef7b3e5afc71617f2a9b0203ad5351a678077690ffe626e1bb6ade1d51bcf"
  "time" => 1521875926
  "sys_fee" => "0"
  "size" => 202
  "scripts" => array:1 [▶]
  "script" => null
  "pubkey" => null
  "nonce" => null
  "net_fee" => "0"
  "description" => null
  "contract" => null
  "claims" => null
  "block_height" => 2059552
  "block_hash" => "1173c981404a74d47d6500b9187366eaf3a53d233be517e2ad69d3c2c243d717"
  "attributes" => []
  "asset_moved" => "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"
  "asset" => null
]

My question is:
1.) Why vin doesn't show the sender address?
2.) there is a lot of attribute that didn't provide description, is it any documentation about model structure? (as example, what is "n" represent in vout?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.