XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.19k stars 507 forks source link

Decimal place found in integerNumberString #2043

Closed sera-korbit closed 1 year ago

sera-korbit commented 1 year ago

When I put any string amount in 'value' field, i always got this error.

for example, when i set trustline, i got that error , signing transaction. what is the reason of this??

const trustSet_tx = {
    TransactionType: 'TrustSet',
    Account:  address, // account that wants to receive the tokens
    LimitAmount: {
      currency: CURRENCY_CODE, // currency code
      issuer: ISSUER, // currency address
      value: '100', // token limit, maximum amount of the token you are willing to hold
    },
  };

  const ts_prepared = await client.autofill(trustSet_tx);
  const wallet = Wallet.fromSeed(seed);
  const tx_signed = wallet.sign(ts_prepared);
  const ts_result = await client.submitAndWait(tx_signed.tx_blob);
JST5000 commented 1 year ago

I'm not quite able to reproduce the issue locally unfortunately. This code works for me:

xrpl = require("xrpl");

async function main() {
  const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
  await client.connect();

  const account1 = "rUBUpo4sddQ9K3MK2CJjWZegFSiXer1aU7";
  const secret1 = "sss3tZHAhZCHkp6JmH9c7H3snrRVX";

  const account2 = "rGAh5M8GH59tmwEYWx8MCSTJbQ88SPCEEF";

  const tx = {
    TransactionType: "TrustSet",
    Account: account1,
    LimitAmount: {
      currency: "000",
      issuer: account2,
      value: "100",
    },
  };

  const ts_prepared = await client.autofill(tx);
  const wallet = xrpl.Wallet.fromSeed(secret1);
  const tx_signed = wallet.sign(ts_prepared);
  const ts_result = await client.submitAndWait(tx_signed.tx_blob);
  console.log("SUCCESS! - ", ts_result)

  await client.disconnect()
}

void main();

Maybe there's a difference between the code you shared above and the code you're actually running? (The error you're getting seems to be intended to trigger if the given value is way too small to be valid, and is triggered in the xrpl.js code here as far as I can tell: https://github.com/XRPLF/xrpl.js/blob/89b88336108c37de19d9ba4fb43f2f1bd70c6215/packages/ripple-binary-codec/src/types/amount.ts#L242)

sera-korbit commented 1 year ago

Thank you for your comment. Maybe I guess there is a conflict with Decimal library in my project.

jinho-korbit commented 1 year ago

@JST5000

The framework for executing th above code is JS-Based Electron. It doesn`t run on Electron, but it works normally if you run only the file through the CLI. Please check. Please refer to the attached file of our package.json

{
  "name": "cust-helper",
  "version": "1.2.32-prod",
  "description": "",
  "scripts": {
    "mocha": "mocha",
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --mode development&&electron .",
    "dev": "electron-webpack --es-module-specifier-resolution=node dev",
    "build": "electron-webpack",
    "dist-prod": "NODE_ENV=production electron-webpack && electron-builder --mac --x64 --publish never",
    "dist-dev": "NODE_ENV=development electron-webpack && electron-builder --mac --x64 --publish never",
    "rebuild": "electron-rebuild",
    "jest": "jest"
  },
  "author": "Korbit Inc",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.12.3",
    "@babel/plugin-proposal-class-properties": "^7.12.1",
    "@babel/preset-env": "^7.12.1",
    "@babel/preset-react": "^7.12.5",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^8.1.0",
    "css-loader": "^5.0.1",
    "electron": "^13.4.0",
    "electron-builder": "^23.0.3",
    "electron-devtools-installer": "^3.2.0",
    "electron-rebuild": "^3.2.3",
    "electron-webpack": "^2.8.2",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.25.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^5.1.0",
    "eslint-plugin-react": "^7.26.1",
    "eslint-plugin-standard": "^5.0.0",
    "html-loader": "^1.3.2",
    "html-webpack-plugin": "^4.5.0",
    "jest": "^27.2.5",
    "prettier": "2.5.1",
    "style-loader": "^2.0.0",
    "webpack": "^4.41.5"
  },
  "dependencies": {
    "@ant-design/icons": "^4.7.0",
    "@aws-sdk/client-kms": "^3.8.1",
    "@aws-sdk/client-s3": "^3.8.1",
    "@aws-sdk/client-secrets-manager": "^3.8.1",
    "@binance-chain/javascript-sdk": "^2.15.0",
    "@cosmjs/launchpad": "^0.25.4",
    "@cosmostation/cosmosjs": "^0.10.5",
    "@dfinity/rosetta-client": "^0.6.0",
    "@elrondnetwork/elrond-core-js": "^2.1.0",
    "@elrondnetwork/erdjs": "^8.0.1-alpha.13",
    "@harmony-js/core": "^0.1.57",
    "@harmony-js/utils": "^0.1.56",
    "@helium/crypto": "^3.38.0",
    "@helium/http": "^3.43.0",
    "@helium/transactions": "^3.38.0",
    "@medibloc/panacea-js": "^1.3.1",
    "@o1labs/client-sdk": "^1.0.1",
    "@oasisprotocol/client": "^0.1.0-alpha1",
    "@onflow/dev-wallet": "0.0.10",
    "@onflow/fcl": "0.0.77",
    "@onflow/sdk": "0.0.55",
    "@onflow/types": "0.0.6",
    "@polkadot/api": "^7.2.1",
    "@polkadot/keyring": "^8.2.2",
    "@polkadot/util-crypto": "^8.2.2",
    "@solana/spl-token": "^0.2.0",
    "@solana/web3.js": "^1.15.0",
    "@terra-money/terra.js": "^1.8.10",
    "@thetalabs/theta-js": "0.0.56",
    "@truffle/hdwallet-provider": "^1.4.0",
    "@vechain/connex": "^2.0.5",
    "@vechain/connex-driver": "^2.0.5",
    "@vechain/connex-framework": "^2.0.5",
    "@zilliqa-js/account": "^3.1.0",
    "@zilliqa-js/blockchain": "^3.1.0",
    "@zilliqa-js/contract": "^3.1.0",
    "@zilliqa-js/core": "^3.1.0",
    "@zilliqa-js/crypto": "^3.1.0",
    "@zilliqa-js/proto": "^3.1.0",
    "@zilliqa-js/util": "^3.1.0",
    "@zilliqa-js/zilliqa": "^3.1.0",
    "@zondax/filecoin-signing-tools": "^0.12.0",
    "aes256": "^1.0.4",
    "antd": "^4.8.2",
    "arweave": "^1.10.23",
    "axios": "^0.21.0",
    "bch-addr-slp": "^0.2.0",
    "bchaddrjs-slp": "^0.2.14",
    "bech32": "^2.0.0",
    "big-integer": "^1.6.48",
    "big-js": "^3.1.3",
    "bignumber.js": "^9.0.1",
    "bip32": "^3.0.1",
    "bip32-utils": "^0.11.1",
    "bip39": "^3.0.3",
    "bitcore-lib": "^8.25.10",
    "bitcore-lib-cash": "^8.25.25",
    "bitcore-mnemonic": "^8.23.1",
    "blob-stream": "^0.1.3",
    "borsh": "^0.7.0",
    "cardano-sdk": "^0.1.1",
    "caver-js": "^1.6.1",
    "clean-webpack-plugin": "^3.0.0",
    "decimal.js": "^10.3.1",
    "elliptic": "^6.5.4",
    "eosjs": "^22.1.0",
    "eth-lib": "^0.1.29",
    "ethereumjs-tx": "^2.1.2",
    "ethereumjs-wallet": "^1.0.1",
    "ethers": "^5.3.0",
    "fetch": "^1.1.0",
    "fs": "0.0.1-security",
    "generate-password": "^1.6.0",
    "human-crypto-keys": "^0.1.4",
    "immer": "^7.0.14",
    "js-base64": "^3.6.0",
    "js-sha256": "^0.9.0",
    "less": "^3.12.2",
    "less-loader": "^7.0.2",
    "libp2p-crypto": "^0.21.2",
    "litecore-lib": "^0.13.22",
    "lodash": "^4.17.21",
    "mocha": "^9.0.2",
    "moment": "^2.29.1",
    "near-api-js": "^0.44.2",
    "near-seed-phrase": "^0.2.0",
    "node-rest-client": "^3.1.0",
    "os": "^0.1.1",
    "pact-lang-api": "^4.3.3",
    "pbkdf2": "^3.1.2",
    "pdfkit": "^0.11.0",
    "postcss-load-config": "^3.0.0",
    "postcss-loader": "^4.0.4",
    "prop-types": "^15.7.2",
    "qrcode": "^1.4.4",
    "react": "^17.0.1",
    "react-copy-to-clipboard": "^5.0.2",
    "react-dom": "^17.0.1",
    "react-json-view": "^1.21.3",
    "react-qr-reader2": "^1.1.0",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.9",
    "redux-saga": "^1.1.3",
    "request": "^2.88.2",
    "request-promise-native": "^1.0.9",
    "rlp": "^2.2.6",
    "secp256k1": "^4.0.3",
    "secrets.js-grempe": "^2.0.0",
    "sha3": "^2.1.4",
    "shamirs-secret-sharing": "^1.0.1",
    "source-map-support": "^0.5.19",
    "thor-devkit": "^2.0.1",
    "tronweb": "^2.7.2",
    "tweetnacl": "^1.0.3",
    "uuid": "^8.3.2",
    "web3": "^1.3.4",
    "web3-eth-contract": "^1.3.4",
    "xrpl": "2.0.0"
  },
  "electronWebpack": {
    "renderer": {
      "webpackConfig": "webpack.config.js"
    }
  }
}
JST5000 commented 1 year ago

@jinho Unfortunately I'm still unable to reproduce with electron JS (I cloned their quickstart they display on their homepage here and added the xrpl code I shared before for signing and submitting a transaction, and it still succeeded)

One thing I did notice however is that you are using xrpl 2.0.0 in your dependencies, when the latest version is 2.3.1 - Maybe using the latest version will solve the problem?

main.js with xrpl code from above added:

// Modules to control application life and create native browser window
const { app, BrowserWindow } = require("electron");
const path = require("path");

xrpl = require("xrpl");

async function main() {
  const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
  await client.connect();

  const account1 = "rUBUpo4sddQ9K3MK2CJjWZegFSiXer1aU7";
  const secret1 = "sss3tZHAhZCHkp6JmH9c7H3snrRVX";

  const account2 = "rGAh5M8GH59tmwEYWx8MCSTJbQ88SPCEEF";

  const tx = {
    TransactionType: "TrustSet",
    Account: account1,
    LimitAmount: {
      currency: "ABC",
      issuer: account2,
      value: "100",
    },
  };

  const ts_prepared = await client.autofill(tx);
  const wallet = xrpl.Wallet.fromSeed(secret1);
  const tx_signed = wallet.sign(ts_prepared);
  const ts_result = await client.submitAndWait(tx_signed.tx_blob);
  console.log("SUCCESS! - ", ts_result);

  await client.disconnect();
}

void main();

function createWindow() {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

  // and load the index.html of the app.
  mainWindow.loadFile("index.html");

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  createWindow();

  app.on("activate", function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", function () {
  if (process.platform !== "darwin") app.quit();
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

To run it I followed the quickstart steps they outlined:

  1. cd electron-quick-start
  2. npm install && npm start
JST5000 commented 1 year ago

Closing this as inactive, feel free to re-open this if it's still ongoing and we can continue troubleshooting.