Giter Site home page Giter Site logo

marvinroger / nanocurrency-js Goto Github PK

View Code? Open in Web Editor NEW
140.0 10.0 31.0 6.35 MB

πŸ”— A toolkit for the Nano cryptocurrency, allowing you to derive keys, generate seeds, hashes, signatures, proofs of work and blocks.

Home Page: https://marvinroger.github.io/nanocurrency-js

JavaScript 0.67% C 29.99% TypeScript 0.60% CSS 0.88% HTML 66.04% Roff 0.03% Makefile 0.05% C# 1.75%
nano currency cryptocurrency raiblocks crypto pow

nanocurrency-js's Introduction

nanocurrency-js

Test

The nanocurrency-js monorepo.

Packages

nanocurrency

npm version

A battle-tested toolkit for the Nano cryptocurrency.

The code lives in packages/nanocurrency/.

nanocurrency-cli

npm version

A CLI for the Nano cryptocurrency. Uses the nanocurrency package.

The code lives in packages/nanocurrency-cli/.


Donations

If you like the project, feel free to donate some nano:

xrb_3mrogerjhkdyj6mzf4e7aatf3xs3gp4stwc9yt9ymgasw7kr7g17t4jwwwy8

nanocurrency-js's People

Contributors

dependabot[bot] avatar marvinroger 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  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

nanocurrency-js's Issues

Failed to minify the code from nanocurrency-js

I'm trying to make a build of my React front end which is using Nanocurrency-js, but I'm getting an error stating that it can't minify the code from nanocurrency-js. The console redirects me here, and it basically says that the code has to be compiled to ES5 before being published to NPM since not all browsers support ES6.

Can't build

trying to build:prod this package I'm hit with the error:

[!] Error: Could not resolve '../assembly' from src/accelerated.ts

Any help ?

Switch to TypeScript

TypeScript would allow compile-time type errors and better developer experience, enhancing the safety of the code.

Slow performance with derivePublicKey(secretKey)

I'm building a reactJS app for finding vanity addresses using this library and web workers to get multithreading. It all works great and the following code does the address creation and matching. However I have problem with performance. Without the derivePublicKey below I can do 150,000 loops per second. With the derivePublicKey the performance drops to 600/s. Another strange thing is that there is no difference using 2 threads or 12 when doing that. Just using "currentAddressesCount += 1" boost the loop count to 120 million per second so nothing wrong with the multithreading implementation. Perhaps there is nothing wrong with your library but maybe you know what's wrong?

function search() {
  currentAddressesCount += 1
  const array = new Uint8Array(32)
  // eslint-disable-next-line no-restricted-globals
  self.crypto.getRandomValues(array)
  const seed = array.reduce((hex, idx) => hex + (`0${idx.toString(16)}`).slice(-2), '')
  const secretKey = nano.deriveSecretKey(seed, 0)
  const publicKey = nano.derivePublicKey(secretKey)
  const address = nano.deriveAddress(publicKey, {useNanoPrefix: true})

  if (isMatch(address)) {
    postMessage(address)
  }
}

Uncaught (in promise) TypeError: Illegal invocation

Thank you for the great work!

While trying out your library in run into the following error in Chrome, while using workers:

nanocurrency.umd.js:6 Uncaught (in promise) TypeError: Illegal invocation

You can reproduce the error by using the following in your multi-threaded example:

await NanoCurrency.init()
const work = await NanoCurrency.generateSeed()

Seems the error comes from here.

Manage to get around by generating the seed myself:

const array = new Uint8Array(32);
self.crypto.getRandomValues(array);
const seed = array.reduce((hex, idx) => {
  return hex + ('0' + idx.toString(16)).slice(-2);
}, '');

_convertAmountDecimalIntegerToHex returning incorrect hex value?

When I use createSendBlock and provide it with a balance in raw the returned hex value seems to be incorrect.

I provide 2000000000000000000000000 in the balance property and the converted value shows 0000000000001A784379D99DB4200000. The converted value I am expecting is 000000000001A784379D99DB42000000. You'll see that they look deceptively similar but if you count the number of zeros at the start and end of both figures you will see that the figure has been 'shifted' one place too many.

I guess the bug must be in the _convertAmountDecimalIntegerToHex function? Thanks!

Allow public key derivation from address

Currently, you can only derive a public key from a secret key. We should allow public key to be derived from addresses, to.

Please vote πŸ‘ if this is important to you.

Feature request add schnorr MuSig N of N

It would be really nice if this lib could support the schnorr MuSig implementation and enable a user friendly api to create and spend from multisigs.

There is a Rust implementation on the nano github here.

There is also the paper and documentation on the blockstream blog here.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Running nanocurrency.deriveAddress() gives me an error in React Native

I'm trying to run the function deriveAddress(publicKey) in React Native, but it throws me an error TypeError: undefined is not a function (evaluating 'AI(i, null, 5).reverse()') which originates from node_modules\nanocurrency\dist\nanocurrency.umd.js:6:36609.

nanocurrency.deriveSecretKey(seed, 0); and nanocurrency.derivePublicKey(privateKey); both work fine. So I guess the problem comes from encodeNanoBase32?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

work() not working...

I can't get work() to do its thing:

const pow = nanoCurrency.work(accountHash);

Outputs:

nanocurrency.esm.js:6 Uncaught (in promise) TypeError: checkHash is not a function at Object.work (http://localhost:3000/static/js/bundle.js:25491:182215)

This is in a react app.

wasm/webassembly bundle

I love the module.

Just a couple of questions:

  • Are C++ files used for performance improvements?
  • Do the bundles have a wasm inclusion? what about the sync WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB limit if ran inside electron/browser? it uses async import?
  • What if in the build command I put -s WASM=0 instead of 1?

Validate work invalid for new PoW threshold introduced in v21

Referring to this: https://github.com/marvinroger/nanocurrency-js/blob/master/packages/nanocurrency/src/work.ts

WORK_THRESHOLD of 0xffffffc000000000 is the default threshold but v21 is introducing a reduced threshold for receive blocks that is 1/8x the default one, that is 0xfffffe0000000000. Validate work will thus be invalid for those blocks. I'm not sure what the best approach is. Lower the threshold or add another parameter to pass in a custom threshold. For the latter, you can then verify against any threshold you want.

Provide helpers for converting units

The goal of the library is to contain everything needed to deal with the Nano currency. We should add helpers to convert units (Nano, nano, raw, NANO...).

Please vote πŸ‘ if this is important to you.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Incorrectly derived address

Hey guys,
I've sent some funds to address derived from private key (should have been pub key, doh).
Is there any way to get the funds back?
Thanks

Switch to all JS (except for work generation)

Doing that should make the package easier to use (no need to call init beforehand), and potentially make the code smaller.

Moreover, it will work on environments with broken WebAssembly support (iOS for example).

Obviously, work generation will still use WebAssembly, for performance.

[Feature Request] Add limit to ComputeWorkParams

I think it would be useful to have something to limit the number of tries of computeWork function.
For example: if after 1 million tries it doesn't find a valid work, it stops instead of keep trying.

Block work is less than threshold

Hi, I've been trying to create a receive block, and no matter how much I raise the threshold the node is always telling me the work is insufficient.
And comparing the work with my friend's work server they are very different.

This is the block

{
    "action": "process",
    "json_block": "true",
    "subtype": "receive",
    "block": {
        "type": "state",
        "account": "xrb_3nxd8aiacqxfakhosxempi5fursjzkxiyrt1jwmco91opuz8qb9njiapkecz",
        "previous": "0000000000000000000000000000000000000000000000000000000000000000",
        "representative": "nano_1qnnxd8z3ugpigfzcyuwmix43uocqzatg8ynxi4owyimnkjsqfxtfo184s6d",
        "balance": "100000000000000000000000000",
        "link": "1B425E78F39AC55C95AFCABF76F30B5CC098844D348B9455F5889AF5C594F61D",
        "link_as_account": "xrb_18t4dswh98p7dkctzkozgusipq81m446tf6dkjczd46tyq4sbxixd96h8hfr",
        "work": "00000000008a2686",
        "signature": "9783BB50597B049C1FD6A13D53DCEBA56CAB6F73D15EDF68203F7FE16CAC351574D104C62919A9EFE0B5D742E5BEDECE9458EFE2A69129C2E1BD281EAFE3BF0F"
    }
}

this is the work my friend provided:

{
    "hash": "D3AB3220855FAD449F5CF593B406DDE331FCBB0F63408F26AA9C15B6FE6BA4F4",
    "work": "c10561ca4a74c418",
    "difficulty": "fffffff80bd6da42",
    "multiplier": "1.005814505536319"
}

I noticed the difficulty is higher than base fffffff800000000

Am I doing something wrong?

UPDATE:
I've tried changing the difficulty to fffffff900000000 and after 13 minutes got 000000004e099dc6 as work, still fails.

Support universal blocks

We should support universal blocks creation (once released).
We need to see how is the integration done on the network to see whether or not we should still support the "legacy" blocks. Anyway, these functions would be depreciated.

How to inject PoW?

In the documentation when creating blocks it states:

You will have to inject the PoW.

however I can't find any example of how to do this. Did I miss an example somewhere? Thanks!

Making open block not possible because previous field is not allowed to be "0"

I'm trying to hash an open block, which according to the Official Nano Wiki should have the field 'previous' equal to 0, but that throws an error. Problem is here:

if (!checkHash(params.previous)) throw new Error('Previous is not valid');
I think the line should be
if (!checkHash(params.previous) || param.previous == '0') throw new Error('Previous is not valid');
but I'm not sure

Basic support - creating a send block createBlock

Feel free to close if this is not the place for support.

I am stuck at the POC stage of generating a valid send block my local node keep spitting out Block is invalid, I feel like I am missing something surrounding core concepts here, but I hit a wall so I figured I would reach out.

Environment:
Node Version - V21.0DB12
NanoCurrency Version - 2.4.0
Execution Environment - Firefox 76.0.1 (browserify)

As far as I can tell the core issue is that I seem to be generating the work incorrectly:
My javascript generated work - 000000000248a56b
The nodes generated work (rpc wallet actions) - aaa4e12ae1b25720

I thought this might be because it is a genesis account and the frontier is not valid for work generation, so I bounced the funds about a bit and used an opened and transacted upon account, but seems to still generate invalid work. (same thing many trailing zeros in the work)

Full info

POC code: ( this is a local genesis account all the data is ephemeral)

var nanocurrency = require('nanocurrency');
var BigNumber = require('bignumber.js');
var rpcurl = 'http://192.168.10.13:7076';

async function rpcall(body) {
  var Init = { method:'POST',body: JSON.stringify(body)};
  var res = await fetch(rpcurl,Init);
  var data = await res.json();
  return data;
}

var sender = 'nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on';
var destination = 'nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax';
var senderprivate = '0C9A87A49A2DD56FE37EF6283A30D32D945BC2B7F2CF675C639C1350AC468204';
var amount = '10000';
var info = {};
info['action'] = 'account_info';
info['representative'] = 'true';
info['account'] = sender;
var res = await rpcall(info);
console.log(res);
console.log('Calculating pow for ' + res.frontier + ' this may take some time')
var pow = await nanocurrency.computeWork(res.frontier);
var balance = new BigNumber(res.balance).minus(new BigNumber(amount)).toFixed();
var block = nanocurrency.createBlock(senderprivate, {
work: pow,
previous: res.frontier,
representative: res.representative,
balance: balance,
link: destination
});
console.log(block);
var send = {};
send['action'] = 'process';
send['json_block'] = 'true';
send['subtype'] = 'send';
send['block'] = block;
var sendres = await rpcall(send);
console.log(sendres);

Account Info:

{
    frontier: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
    open_block: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
    representative_block: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
    balance: "340282366920938463463374607431768211455",
    modified_timestamp: "1589476181",
    block_count: "1",
    account_version: "0",
    confirmation_height: "1",
    confirmation_height_frontier: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
    representative: "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on"
}

Generated Block:

{
  account: "xrb_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
  balance: "340282366920938463463374607431768201455",
  link: "8AEBEA07B03926543942C95A38793FA05C7731D2209B1DEB61C0F60C4389468D",
  link_as_account: "nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax",
  previous: "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
  representative: "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
  signature: "DA8B7A1BD949D743EE767D477F014116F2B7ABEAF75A6E5335C5F0D6FC12A81839ABF88EB81702304A83204AB4EA80B7026345BF0D1B5F299A04B037D8CE1A02",
  type: "state",
  work: "000000000248a56b"
}

The Block that an RPC send command generates:

{
  "type": "state",
  "account": "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
  "previous": "4C49618F2B4B5DA9120847D92B261C68DFEEBD8F6BADB93619D00E1B5E2902FD",
  "representative": "nano_1rxzhkj8jhodn338k65uesk8jk8zxsmyidbw4gtaus984pxc63xbatbfm8on",
  "balance": "340282366920938463463374607431768201455",
  "link": "8AEBEA07B03926543942C95A38793FA05C7731D2209B1DEB61C0F60C4389468D",
  "link_as_account": "nano_34qdxa5u1gb8ciwn7kct93wmza4wgwrx6a6u5qop5i9p3j3rkjnf61q5uxax",
  "signature": "2300B3B178CEE95CE5E839037418E53FCFAEBD48E1FE06C2ED40174E8A121A8DD2660BE31D60089739328A589844915FC7F04C1EA348409587E8D3287A04940C",
  "work": "aaa4e12ae1b25720"
}

Failed to npm install nanocurrency

npm install nanocurrency

npm ERR! Linux 4.4.0
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "nanocurrency"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ENOSELF

npm ERR! Refusing to install nanocurrency as a dependency of itself
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request:
npm ERR! /root/NanoCurrency-js/nanocurrency-js-master/npm-debug.log

In npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'install', 'nanocurrency' ]
2 info using [email protected]
3 info using [email protected]
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData nanocurrency
8 silly fetchNamedPackageData nanocurrency
9 silly mapToRegistry name nanocurrency
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry https://registry.npmjs.org/
12 silly mapToRegistry uri https://registry.npmjs.org/nanocurrency
13 verbose request uri https://registry.npmjs.org/nanocurrency
14 verbose request no auth needed
15 info attempt registry request try #1 at 5:56:21 PM
16 verbose request id 078688e1390353fa
17 verbose etag "5a9f21a5-b124"
18 verbose lastModified Tue, 6 Mar 2018 23:17:57 GMT
19 http request GET https://registry.npmjs.org/nanocurrency
20 http 304 https://registry.npmjs.org/nanocurrency
21 verbose headers { date: 'Wed, 07 Mar 2018 17:56:21 GMT',
21 verbose headers via: '1.1 varnish',
21 verbose headers 'cache-control': 'max-age=300',
21 verbose headers etag: '"5a9f21a5-b124"',
21 verbose headers age: '362',
21 verbose headers connection: 'keep-alive',
21 verbose headers 'x-served-by': 'cache-ord1735-ORD',
21 verbose headers 'x-cache': 'HIT',
21 verbose headers 'x-cache-hits': '1',
21 verbose headers 'x-timer': 'S1520445382.667878,VS0,VE1',
21 verbose headers vary: 'Accept-Encoding, Accept' }
22 silly get cb [ 304,
22 silly get { date: 'Wed, 07 Mar 2018 17:56:21 GMT',
22 silly get via: '1.1 varnish',
22 silly get 'cache-control': 'max-age=300',
22 silly get etag: '"5a9f21a5-b124"',
22 silly get age: '362',
22 silly get connection: 'keep-alive',
22 silly get 'x-served-by': 'cache-ord1735-ORD',
22 silly get 'x-cache': 'HIT',
22 silly get 'x-cache-hits': '1',
22 silly get 'x-timer': 'S1520445382.667878,VS0,VE1',
22 silly get vary: 'Accept-Encoding, Accept' } ]
23 verbose etag https://registry.npmjs.org/nanocurrency from cache
24 verbose get saving nanocurrency to /root/.npm/registry.npmjs.org/nanocurrency/.cache.json
25 silly install normalizeTree
26 silly loadCurrentTree Finishing
27 silly loadIdealTree Starting
28 silly install loadIdealTree
29 silly cloneCurrentTree Starting
30 silly install cloneCurrentTreeToIdealTree
31 silly cloneCurrentTree Finishing
32 silly loadShrinkwrap Starting
33 silly install loadShrinkwrap
34 silly loadShrinkwrap Finishing
35 silly loadAllDepsIntoIdealTree Starting
36 silly install loadAllDepsIntoIdealTree
37 silly rollbackFailedOptional Starting
38 silly rollbackFailedOptional Finishing
39 silly runTopLevelLifecycles Starting
40 silly runTopLevelLifecycles Finishing
41 silly install printInstalled
42 verbose stack Error: Refusing to install nanocurrency as a dependency of itself
42 verbose stack at checkSelf (/usr/share/npm/lib/install/validate-args.js:40:14)
42 verbose stack at Array. (/usr/share/npm/node_modules/slide/lib/bind-actor.js:15:8)
42 verbose stack at LOOP (/usr/share/npm/node_modules/slide/lib/chain.js:15:14)
42 verbose stack at chain (/usr/share/npm/node_modules/slide/lib/chain.js:20:5)
42 verbose stack at /usr/share/npm/lib/install/validate-args.js:15:5
42 verbose stack at /usr/share/npm/node_modules/slide/lib/async-map.js:52:35
42 verbose stack at Array.forEach (native)
42 verbose stack at /usr/share/npm/node_modules/slide/lib/async-map.js:52:11
42 verbose stack at Array.forEach (native)
42 verbose stack at asyncMap (/usr/share/npm/node_modules/slide/lib/async-map.js:51:8)
43 verbose cwd /root/NanoCurrency-js/nanocurrency-js-master
44 error Linux 4.4.0
45 error argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "nanocurrency"
46 error node v4.2.6
47 error npm v3.5.2
48 error code ENOSELF
49 error Refusing to install nanocurrency as a dependency of itself
50 error If you need help, you may report this error at:
50 error https://github.com/npm/npm/issues
51 verbose exit [ 1, true ]

Block work is less than threshold

I'm trying to generate blocks using an external signing service but I'm running into an issue when I attempt to run the process rpc command on the payload that I craft. Here's a general outline of the code:

const accountInfo = await rpc.request('account_info', {
    representative: true,
    account,
});
const accountBalance = new BigNumber(accountInfo.balance);
const balance = new BigNumber(accountInfo.balance).minus(amount);
const params = {
    type: 'state',
    previous: accountInfo.frontier,
    account: account,
    representative: accountInfo.representative,
    balance: balance.toString(10),
    link: withdrawToAddress,
};
const blockHash = await nano.hashBlock(params);
params.signature = nano.signBlock({ hash: blockHash, secretKey });
const workResult = await rpc.request('work_generate', { hash: blockHash });
params.work = workResult.work;
const res = await rpc.request('process', { block: JSON.stringify(params) });

When I attempt to run process it gives me an error back saying Block work is less than threshold.

Some folks on the nano discord suggested that I instead input the previous blocks hash (i.e. accountInfo.frontier) into the work_generate RPC call, but then I get the error Bad signature. Any ideas where I'm going wrong? If I run create_block via RPC with these same values (type, previous, account, representative, balance, link, key == secretKey) it generates a valid block that can be sent, but my way using nanocurrency doesn't seem to work.

Any help or ideas you may have would be exceptionally helpful! I wouldn't mind writing a few examples for this project if you'd like to have some?

Can't create block with balance = "0"

I'm trying to make a send block
nanocurrency.createBlock(privateKey, { balance: "0", link: link, previous: previous, representative: representative, work: null });,
but I'm getting a 'Balance is not valid' error. I'm simply trying to send all Nanos away from an account, so balance = "0" should be valid.

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.