How to use the default function from bn.js
Find comprehensive JavaScript bn.js.default code examples handpicked from public code repositorys.
bn.js.default is a function in the BN.js library that can be used to create a new instance of a big number object for performing arbitrary precision arithmetic in JavaScript.
GitHub: GooseFX1/gfx-web-app
35 36 37 38 39 40 41 42 43 44
return new PublicKeyLayout(property); } exports.publicKeyLayout = publicKeyLayout; class BNLayout extends buffer_layout_1.Blob { decode(b, offset) { return new bn_js_1.default(super.decode(b, offset), 10, 'le'); } encode(src, b, offset) { return super.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset); }
GitHub: GooseFX1/gfx-web-app
285 286 287 288 289 290 291 292 293 294
owner, ...signers, ]); } getSplTokenBalanceFromAccountInfo(accountInfo, decimals) { return divideBnToNumber(new bn_js_1.default(accountInfo.data.slice(64, 72), 10, 'le'), new bn_js_1.default(10).pow(new bn_js_1.default(decimals))); } get supportsSrmFeeDiscounts() { return (0, fees_1.supportsSrmFeeDiscounts)(this._programId); }
+ 16 other calls in file
How does bn.js.default work?
bn.js.default
is a function in the BN.js library that can be used to create a new instance of a big number object for performing arbitrary precision arithmetic in JavaScript.
When bn.js.default
is called, it takes a single argument, which is the initial value of the big number object. This value can be a number, a string, or another big number object.
Once the big number object is created, it can be used to perform arithmetic operations using methods such as add
, sub
, mul
, or div
.
The big number object also provides methods for performing bitwise operations, comparison operations, and conversion to and from other data types.
By default, bn.js.default
uses 256-bit precision for arithmetic operations, but this can be customized using various options, such as size
, endian
, or prime
.
Overall, bn.js.default
provides a powerful way to perform arbitrary precision arithmetic in JavaScript, allowing developers to work with large numbers that cannot be represented by the built-in JavaScript number type.
GitHub: keypom/keypom-js
351 352 353 354 355 356 357 358 359 360
catch (e) { console.log('e: ', e); incomingGas = "200000000000000"; } console.log('incomingGas: ', incomingGas); gasToAttach = new bn_js_1.default('35000000000000').add(new bn_js_1.default(incomingGas)).toString(); // check if the gas to attach is over 300 TGas and if it is, clamp it if (new bn_js_1.default(gasToAttach).gt(new bn_js_1.default('300000000000000'))) { console.log('gas to attach is over 300 TGas. Clamping it'); gasToAttach = '300000000000000';
+ 8 other calls in file
210 211 212 213 214 215 216 217 218 219
}); } // If !maxAttachableYoctoPerContract, create an array of the same size as callableMethods and fill it with "*" if (!maxAttachableYoctoPerContract) maxAttachableYoctoPerContract = Array(callableMethods.length).fill("*"); attachedDeposit = new bn_js_1.default(trialFundsYocto).add(new bn_js_1.default(parseNearAmount("0.3"))).toString(); rootReceiverId = (_w = finalConfig.root_account_id) !== null && _w !== void 0 ? _w : (networkId == "testnet" ? "testnet" : "mainnet"); createDropArgs = { drop_id: dropId, public_keys: publicKeys || [],
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const BN = require("bn.js"); // Create a new big number object with an initial value of 42 const myNumber = new BN("42"); // Perform arithmetic operations on the big number object const addResult = myNumber.add(new BN("10")); const subResult = myNumber.sub(new BN("5")); const mulResult = myNumber.mul(new BN("2")); const divResult = myNumber.div(new BN("3")); console.log("Add result:", addResult.toString()); console.log("Subtract result:", subResult.toString()); console.log("Multiply result:", mulResult.toString()); console.log("Divide result:", divResult.toString());
In this example, we use bn.js.default to create and perform arithmetic operations on a big number object. We call new BN('42') to create a new big number object with an initial value of 42. We then perform various arithmetic operations on the big number object using methods such as add, sub, mul, and div, passing them other big number objects as arguments. We log the results of the arithmetic operations to the console, using the toString method to convert the big number objects to strings for display. This example shows how bn.js.default can be used to perform arbitrary precision arithmetic operations on large numbers in JavaScript. By creating big number objects with bn.js.default and using its arithmetic methods, we can work with numbers that cannot be represented by the built-in JavaScript number type.
GitHub: keypom/keypom-js
354 355 356 357 358 359 360 361 362 363
})]; case 10: requiredDeposit = _8.sent(); hasBalance = false; if (!useBalance) return [3 /*break*/, 12]; _h = bn_js_1.default.bind; return [4 /*yield*/, (0, views_1.getUserBalance)({ accountId: account.accountId })]; case 11: userBal = new (_h.apply(bn_js_1.default, [void 0, _8.sent()]))(); if (userBal.lt(new bn_js_1.default(requiredDeposit))) {
+ 8 other calls in file
GitHub: keypom/keypom-js
82 83 84 85 86 87 88 89 90 91
var GAS_PER_CCC = 5000000000000; // 5 TGas var RECEIPT_GAS_COST = 2500000000000; // 2.5 TGas var YOCTO_PER_GAS = 100000000; // 100 million exports.ATTACHED_GAS_FROM_WALLET = 100000000000000; // 100 TGas /// How much yoctoNEAR it costs to store 1 access key var ACCESS_KEY_STORAGE = new bn_js_1.default("1000000000000000000000"); var key2str = function (v) { return typeof v === 'string' ? v : v.pk; }; exports.key2str = key2str; var hashBuf = function (str, fromHex) { if (fromHex === void 0) { fromHex = false; }
+ 16 other calls in file
53 54 55 56 57 58 59 60 61 62
// airdrop to fund the wallet - may fail occasionally since it defaults to public devnet const sig = yield (0, functions_1.airdrop)(squads.connection, walletKeypair.publicKey, web3_js_1.LAMPORTS_PER_SOL); const multisigAccount = yield squads.createMultisig(threshold, createKey, members, name, description); console.log("Successfully created a new multisig at", multisigAccount.publicKey.toBase58()); console.log('Multisig account:', JSON.stringify(multisigAccount)); const [vault] = yield (0, sdk_1.getAuthorityPDA)(multisigAccount.publicKey, new bn_js_1.default(1), sdk_1.DEFAULT_MULTISIG_PROGRAM_ID); console.log("Default Vault address:", vault.toBase58()); } catch (e) { console.log('Error:', e);
+ 2 other calls in file
bn.js.prototype is the most popular function in bn.js (15750 examples)