Coder Social home page Coder Social logo

neb.php's Introduction

neb.php

neb.php is the Nebulas compatible PHP API. Users can sign/send transactions and deploy/call smart contract with it.

Requirements

neb.php requires the following:

Installation

You can install this library via Composer:

composer require nebulas/neb.php

Or add this in your composer.json:

"require": {
    "nebulas/neb.php": "0.0.2"
}

And also you can clone this repo or download it as zip file. Then don't forget to run composer install under the project root to have the dependencies installed.

Usage

please refer to examples to learn how to use neb.php.

Account

use Nebulas\Core\Account;

$account = Account::newAccount();
//$account = new Account();     //This is the same as above
$addr = $account->getAddressString(); //such as "n1HUbJZ45Ra5jrRqWvfVaRMiBMB3CACGhqc"  
$keyStore = $account->toKey();  //Please save your keyStore(json) in to file and keep it safe

API

use Nebulas\Rpc\HttpProvider;
use Nebulas\Rpc\Neb;

$neb = new Neb(new HttpProvider("https://testnet.nebulas.io"));

$api = $neb->api;
echo $api->getAccountState("n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6"), PHP_EOL;;
echo $api->getTransactionReceipt("8b98a5e4a27d2744a6295fe71e4f138d3e423ced11c81e201c12ac8379226ad1"), PHP_EOL;

Transaction

use Nebulas\Rpc\Neb;
use Nebulas\Rpc\HttpProvider;
use Nebulas\Core\Account;
use Nebulas\Core\Transaction;
use Nebulas\Core\TransactionBinaryPayload;
use Nebulas\Core\TransactionCallPayload;

$neb = new Neb();
$neb->setProvider(new HttpProvider("https://testnet.nebulas.io"));

$keyJson = '{"version":4,"id":"814745d0-9200-42bd-a4df-557b2d7e1d8b","address":"n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6","crypto":{"ciphertext":"fb831107ce71ed9064fca0de8d514d7b2ba0aa03aa4fa6302d09fdfdfad23a18","cipherparams":{"iv":"fb65caf32f4dbb2593e36b02c07b8484"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dddc4f9b3e2079b5cc65d82d4f9ecf27da6ec86770cb627a19bc76d094bf9472","n":4096,"r":8,"p":1},"mac":"1a66d8e18d10404440d2762c0d59d0ce9e12a4bbdfc03323736a435a0761ee23","machash":"sha3256"}}';
$password = 'passphrase';

$from = Account:: fromKey($keyJson, $password);

//get nonce value
$resp = $neb->api->getAccountState($fromAddr);
$respObj = json_decode($resp);
$nonce = $respObj->result->nonce;

//make new transaction
$chainId = 1001;
$to = "n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6";
$tx = new Transaction($chainId, $from, $to, $value = "0", $nonce + 1 );
$tx->hashTransaction();
$tx->signTransaction();

//send transaction
$result = $neb->api->sendRawTransaction($tx->toProtoString());

Join in!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue.

neb.php's People

Contributors

lanmerry avatar yupnano avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

neb.php's Issues

PHP API查询数据

$neb = new Neb(new HttpProvider("https://testnet.nebulas.io"));
$api = $neb->api;  
上面这两句能打印出来
   echo $api->getNebState(), PHP_EOL;     从这里开始就输出没有东西了,这是为什么,
    $resp = $api->getAccountState("n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6");
   $respObj = json_decode($resp);
   var_dump($respObj);die;
   $nonce = $respObj->result->nonce;
    $resp = $api->call("n1JmhE82GNjdZPNZr6dgUuSfzy2WRwmD9zy",
"n1JmhE82GNjdZPNZr6dgUuSfzy2WRwmD9zy",
"100000",
$respObj->result->nonce + 1,
"200000",
"200000");

密码错误

我密码获取keystore私钥,密码输入正确,验证mac一直密码错误。用你的kestore正常,我的就没法。麻烦看看

PHP API查询数据

$neb = new Neb(new HttpProvider("https://testnet.nebulas.io"));
$api = $neb->api;  
上面这两句能打印出来
   echo $api->getNebState(), PHP_EOL;     从这里开始就输出没有东西了,这是为什么,
    $resp = $api->getAccountState("n1H2Yb5Q6ZfKvs61htVSV4b1U2gr2GA9vo6");
   $respObj = json_decode($resp);
   var_dump($respObj);die;
   $nonce = $respObj->result->nonce;
    $resp = $api->call("n1JmhE82GNjdZPNZr6dgUuSfzy2WRwmD9zy",
"n1JmhE82GNjdZPNZr6dgUuSfzy2WRwmD9zy",
"100000",
$respObj->result->nonce + 1,
"200000",
"200000");

elliptic-php 这个能兼容向上吗?

Using version ^0.0.2 for nebulas/neb.php
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Can only install one of: simplito/elliptic-php[1.0.6, 1.0.4].
- Can only install one of: simplito/elliptic-php[1.0.4, 1.0.6].
- Can only install one of: simplito/elliptic-php[1.0.4, 1.0.6].
- nebulas/neb.php 0.0.2 requires simplito/elliptic-php 1.0.4 -> satisfiable by simplito/elliptic-php[1.0.4].
- Installation request for nebulas/neb.php ^0.0.2 -> satisfiable by nebulas/neb.php[0.0.2].
- Installation request for simplito/elliptic-php (locked at 1.0.6) -> satisfiable by simplito/elliptic-php[1.0.6].

我这边使用了有这个了,你这个是固定死了版本,能修改兼容吗?
"simplito/elliptic-php": "^1.0"

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.