Code Monkey home page Code Monkey logo

neb.js's Introduction

Nebulas JavaScript API

NPM

This is the Nebulas compatible JavaScript API. Users can use it in browser and node.js. This javascript library also support API for our Repl console. Users can sign/send transactions and deploy/call smart contract with it. neb.js

Install && Package

Use the npm installation dependencies

npm install

Use gulp to package the neb.js:

gulp

Now we can check the newly created files in /dist

Here you should see a bunch of js files.

  • neb.js:Used in browser side. Only RPC interface supported.
  • neb-light.js:Used in Repl console. Not including outside dependency.
  • nebulas.js: Fully functional in the browser. Users can create an address, sign a transaction, and deploy/call a smart contract.
CDN Support

neb.js has been released to NPM, and developers can use the following code through CDN addition.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/nebulas.js"></script>

Documentation

Public API documentation link

For build API documentation run gulp documentation task.

Generated documentation you can check in /documentation folder.

Usage

neb.js is a useful library for nebulas developers. It provides rich underlying support in web and node.js's dapp. It implements the following functions.

  • The RPC interface for the nebulas node is encapsulated;
  • Create and manage the private key and address of the nebulas;
  • Generate the transaction object and sign the transaction.
  • Deploy/call smart contract, breakpoint debugging support.

The use of neb.js can be used as examples:

Contribution

We are very glad that you are considering to help Nebulas Team or go-nebulas project, including but not limited to source code, documents or others.

If you'd like to contribute, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on our slack channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.

Please refer to our contribution guideline for more information.

Thanks.

License

The go-nebulas project is licensed under the GNU Lesser General Public License Version 3.0 (“LGPL v3”).

For the more information about licensing, please refer to Licensing page.

neb.js's People

Contributors

1c7 avatar bibibong avatar bogdandidenko avatar chengorangeju avatar fbzhong avatar includeleec avatar nebulashub avatar ottokafka avatar qywang2012 avatar silentttttt avatar xbhuang1994 avatar yupnano avatar yuxizhe 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neb.js's Issues

Publish standalone neb.js in browser on CDN like cdnjs, jsDelivr

Hi,

It's would be much easier to use standalone neb.js (nebulas.js) in browser with public CDN url, like:
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js

I think cdnjs and jsDelivr are good sites for hosting:

jsDelivr: https://www.jsdelivr.com/

CDNJS: https://cdnjs.com/

For the new library request issue, please make sure it's not a personal project, we have a basic requirement for the popularity, like 200 stars on GitHub or 800 downloads/month on npm registry.

Gulp failed with AssertionError

Using the current package.json dependency setting "gulp": ">=3.9.0",version 4.0.0 of gulp-cli is automatically installed.
Setting should be set such that only the version 3 of gulp-cli is installed instead.

Error obtained with gulp v4:

yarn build v0.24.6
$ gulp
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (/Users/ericluwj/Projects/neb.js/node_modules/undertaker/lib/set-task.js:10:3)
    at Gulp.task (/Users/ericluwj/Projects/neb.js/node_modules/undertaker/lib/task.js:13:8)
    at Object.<anonymous> (/Users/ericluwj/Projects/neb.js/gulpfile.js:71:6)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at execute (/Users/ericluwj/Projects/neb.js/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:36:18)
    at Liftoff.handleArguments (/Users/ericluwj/Projects/neb.js/node_modules/gulp-cli/index.js:175:63)
    at Liftoff.execute (/Users/ericluwj/Projects/neb.js/node_modules/liftoff/index.js:203:12)
    at module.exports (/Users/ericluwj/Projects/neb.js/node_modules/flagged-respawn/index.js:51:3)
    at Liftoff.<anonymous> (/Users/ericluwj/Projects/neb.js/node_modules/liftoff/index.js:195:5)
    at /Users/ericluwj/Projects/neb.js/node_modules/liftoff/index.js:165:9
error Command failed with exit code 1.

rpc请求没有添加超时控制

rpc请求没有超时控制,如果请求出去之后一直没有响应的话会一直等待, httprequest包里有this.timeout选项, 好像没有用用上

The gulp incompatible node v10.0.0

Environment:
neb.js git:(master) ✗ node -v v10.0.0

gulp run abort:
gulp gulp[84896]: ../src/node_contextify.cc:631:static void node::contextify::ContextifyScript::New(const FunctionCallbackInfo<v8::Value> &): Assertionargs[1]->IsString()' failed.
1: node::Abort() [/usr/local/bin/node]
2: node::Assert(char const* const () [4]) [/usr/local/bin/node]
3: node::contextify::ContextifyScript::New(v8::FunctionCallbackInfov8::Value const&) [/usr/local/bin/node]
4: v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo
) [/usr/local/bin/node]
5: v8::internal::MaybeHandlev8::internal::Object v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate*, v8::internal::Handlev8::internal::HeapObject, v8::internal::Handlev8::internal::HeapObject, v8::internal::Handlev8::internal::FunctionTemplateInfo, v8::internal::Handlev8::internal::Object, v8::internal::BuiltinArguments) [/usr/local/bin/node]
6: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
7: 0x18b90a18427d
8: 0x18b90a18f755
9: 0x18b90a20bc20
10: 0x18b90a1944f7
11: 0x18b90a1944f7
12: 0x18b90a1944f7
[1] 84896 abort gulp
`

Maybe official release final dist js for us ,so we don't need to build it ourself.

gulp failed, missing some dependency modules

Hi guys,
Finished 'npm install' then execute 'gulp', some exceptions throw as below
[20:59:53] Using gulpfile ~/Workspace/blockchain_area/neb.js/gulpfile.js
[20:59:53] Starting 'documentation'...
[20:59:53] FATAL: Unable to load template: Cannot find module 'moment'

[20:59:53] JSDoc returned with error code: 1
[20:59:53] 'documentation' errored after 715 ms

[21:02:41] FATAL: Unable to load template: Cannot find module 'sanitize-html'

[21:02:41] JSDoc returned with error code: 1
[21:02:41] 'documentation' errored after 1.09 s

After running 'npm install moment sanitize-html --save-dev' it works, I think you should append these two dependencies to the package.json

[bug]After upgrading to 0.5.1, NVM is exported by default, but native.js is imported by default in NVM, which causes the standard Date and Math objects to be replaced, and reports that 'Blockchain.block' is not defined.

升级到 0.5.1 后,默认导出了 NVM。index.js 第 8 行

var NVM = require('./lib/nvm/nvm');

但是 NVM 里面默认引入了 native.js 。nvm.js 第 4 行

var native = require("./native");

native.js 会导致在浏览器环境下标准 Date 和 Math 对象被替换

而且会报 'Blockchain.block' is not defined.(因为Date对象依赖 Blockchain.block,而浏览器环境没有这个)

建议默认不要导出 NVM

存储区变量赋值操作生效时机及是否是原子操作的问题?

现在有个需求是想【满足某个条件的时候触发一方法执行,且该方法只允许执行一次】

目前实现思路是在中心化 server 判断当区块高度变化时轮询合约runGame方法,runGame方法中通过修改gameStatus的值

case 2:
if ( nowBlockH > openPrizeH) {
      this.gameStatus = 3;
}
break;
case 3:
if( !hasEnterOpenPriceMethod(period)) {    //hasEnterOpenPriceMethod方法中修改了一个存储区的变量用来标记当期游戏已进入过开奖方法
      openPrizeH();
}
break;

问题 this.gameStatus = 3; 这个操作的生效是需要整个 tx success 之后呢 还是说方法体中执行过这个语句之后立即生效呢?
这个赋值操作是原子操作吗?(会立即反应到存储区吗?)

感谢!~

numeric overflow

code like:
var tx = new nebulas.Transaction(1, sAccount, toAddress, "9999999999999999999999", nonce, 1000000, 2000000); tx.signTransaction(); neb.api.sendRawTransaction({data:tx.toProtoString()})
value 这里数值溢出,交易发送成功, 在 explorer 中可以看到一直处于 pending 状态, 一段时间后才展示 fail

Error using chrome with third-party cookies blocked

This library does not load correctly when used in chrome for users with third-party cookies disabled.

When users have this setting enabled, localStorage is blocked.
https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

The error in dev tools is "Failed to read the 'localStorage' property from 'Window': Access is denied for this document."

This affects code in native.js which has calls to localStorage.

This might be fixed by wrapping the localStorage aspects in a try/catch. Or there may be some other clever way.

Related to iancoleman/bip39#395

neb.js 在safari打开抛异常

自己项目,引入 neb.js 后:

异常:

Unexpected token '...'. Expected a parameter pattern or a ')' in parameter list.

然后尝试看看官方的demo,发现也出现该异常。

image

This function's cyclomatic complexity is too high.

gulp
[02:58:45] Using gulpfile F:\Workspace\Single\dapps\web-views\neb.js\gulpfile.js
[02:58:45] Starting 'version'...
[02:58:45] Finished 'version' after 7.96 ms
[02:58:45] Starting 'lint'...
[02:58:45] Starting 'documentation'...
lib\account.js: line 278, col 21, This function's cyclomatic complexity is too high. (17)
lib\account.js: line 351, col 23, This function's cyclomatic complexity is too high. (10)

2 errors
[02:58:45] Finished 'lint' after 269 ms
[02:58:45] Starting 'clean'...
[02:58:45] Finished 'clean' after 3.89 ms
[02:58:45] Starting 'light'...
[02:58:45] Starting 'neb'...
[02:58:45] Starting 'request'...
[02:58:45] Starting 'account'...
[02:58:45] Starting 'transaction'...
[02:58:45] Starting 'nebulas'...
[02:58:47] Finished 'light' after 1.51 s
[02:58:47] Documented 12 files!
[02:58:47] Finished 'documentation' after 1.81 s
[02:58:49] Finished 'neb' after 3.03 s
[02:58:50] Finished 'request' after 4.79 s
[02:58:52] Finished 'account' after 6.16 s
[02:58:52] Finished 'nebulas' after 6.15 s
[02:58:52] Finished 'transaction' after 6.16 s
[02:58:52] Starting 'default'...
[02:58:52] Finished 'default' after 51 μs

node -v
v8.9.3

"claim tokens" in example.html 404

2018-August-20

1. Expect

claim Testnet token successfully when click "claim token"
image

Note: I did some change to source code, so in above screenshot, part of text is in Chinese. the original example.html is all English

2. What actually happen

I get 404 error

image
image

Please fix it

image

General Question: How to build Nebulas SDK for different language?

This is a general question, not about neb.js alone. I just want post it here :)

Question: How to build Nebulas SDK for different language?

Base on my understanding:

  1. Implement RPC
  • GetNebState
  • GetAccountState
  • LatestIrreversibleBlock
  • Call
  • SendRawTransaction
  • GetBlockByHash
  • GetBlockByHeight
  • GetTransactionReceipt
  • GetTransactionByContract
  • GetGasPrice
  • EstimateGas
  • GetEventsByHash
  • Subscribe
  • GetDynasty
  1. Implement RPC-admin
  • NodeInfo
  • Accounts
  • NewAccount
  • UnLockAccount
  • LockAccount
  • SignTransactionWithPassphrase
  • SendTransactionWithPassphrase
  • SendTransaction
  • SignHash
  • StartPprof
  • GetConfig

Essentially what SDK does is

Send HTTP request to certain address with correct format

Question: Are my assumption correct?

These 2 step are all it take to build a Nebulas SDK? just implement rpc and rpc-admin base on document link above, is there anything else?

I am not trying to build a Nebulas SDK right now, I am just curious How to build one

Thanks

如何订阅Event Trigger 中的事件?

比如说一个NRC20的 transfer事件, 当一个账户调用了transfer方法后,虽然有调用transferEvent, 但是没有文档写明如何才能订阅到这个事件。

以太坊的是可以监听到这样的事件的。星云文档里面好像没有说明。

用处之一,比如说有其他人给我的地址transfer了token,我需要可以被通知到这个事件进行处理, 不知道星云对这种需求时如何处理的。 在网上未找到相应的文档。 只看到了getEventsByHash这个相关的方法,但是这个需要有hash才行,问题是别人给我transfer了token,我肯定是不知道他的交易hash的,所以这个方法也是没有用。

还请帮忙解答下。

使用了subscribe 方法,但是按照文档中代码来使用的时候报错。
代码如下:

var Nebulas = require('./index')

var Neb = Nebulas.Neb;
var neb = new Neb();
neb.api.subscribe({"topics": ["chain.contract.TestContract"]}).then(function(eventData) {
    console.log(JSON.stringify(eventData));
}).catch(function (e) { console.log("error:" + e) });

但是过一段时间会报下面的错误:

Unexpected token < in JSON at position 0

Add support for BIP39 mnemonic

Something like convertMnemonice(mnemonicPhrase, addressIndex), which takes bip39 mnemonic, converts it to proper private key, according to index, and returns both private key and NAS wallet.

addressIndex is used in BIP32 path, used for generating private key from mnemonic entropy.

This standarts are widely used in all hardware wallets, so it will come handy, adding support for them, and building interfaces to manage private keys for users.

More information:
https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki

Neb API arguments check

Nebulas currently have a usable js version to create the wallet address and send the transaction. Neb. js implements all the RPC interfaces of the Nebulas, but none of these interfaces currently add parameter validation.

We should add parameter validation to these interfaces and functions.

RPC interfaces:

Functions

  • Transaction: The parameters of the constructor need to be checked.
    • chainID should be valid(1 Mainnet, 100[1/2/...] Testnet)
    • from must be a valid address with a private key
    • nonce must be a number

Difference between neb.js and nebulas.js

README say:

image
I still don't know when to use which.

File size have huge difference

image

Question

What the difference between these 2 file neb.js and nebulas.js?
What can I do with these 2?

Accurate ErrorType or ErrorCode need

Now, exceptions thrown from neb.js are all common Error Type, I think we need Accurate ErrorType or different error code to indicate the really exception it is.

Always response: Error: invalid argument(s) . when call sendRawTranscation on nodejs side

Hey
when i try to send transaction by api 'sendRawTransaction' on nodejs side, it always result in error like below:

Error: invalid argument(s)
    at /Users/jazz/Desktop/个人/NAS钱包/proj/nodeserver/node_modules/nebulas/lib/httprequest.js:48:19
    at <anonymous>
    at process._tickCallback `(internal/process/next_tick.js:188:7)

may anyone has ideals, i test it on testnet: https://testnet.nebulas.io/ and my code is:

var callContract = function(params) {
    neb.api.getAccountState(params.from).then(function (resp) {
        params.nonce = parseInt(resp.nonce) + 1;
        var gTx = new nebulas.Transaction(globalParams.chainId,
        globalParams.account,params.to, params.value, params.nonce, params.gasPrice, params.gasLimit, params.contract);

        console.log(gTx);

        gTx.signTransaction();

        console.log(gTx);

        neb.api.sendRawTransaction(gTx.toProtoString()).then(function (resp) {
            console.log(JSON.stringify(resp));
        })
        .catch(function (err) {
            console.log(err);
        });
    });
};

receiptTransaction

receiptTransaction函数内promise返回处理函数有问题,应该是写在then后面。

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.