how to send xrp tokens using bitgo - node.js

const BitGoJS = require(__dirname + '/BitGoJS/src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const coin = 'txrp';
const basecoin = bitgo.coin(coin);
// TODO: set your access token here
const accessToken = 'xxxxxxxxxx';
const walletId = 'xxxxxxxxxx';
// TODO: set your passphrase here
const walletPassphrase = 'xxxxxxxxxxxx';
Promise.coroutine(function *()
{
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
bitgo.unlock({ otp: '0000000' }).then(function(unlockResponse) {
});
let user_walletId = 'xxxx';
const walletInstance = yield basecoin.wallets().get({ id: walletId });
const wallet = yield basecoin.wallets().get({ id: user_walletId });
const newReceiveAddress1 = wallet.receiveAddress();
console.log('receiveAddress is :'+newReceiveAddress1);
console.log('Balance is: ' + (walletInstance.balance() / 1e8).toFixed(4));
const transaction = yield walletInstance.sendMany
({
recipients: [
{
amount: '0.1' * 1e8,
address: newReceiveAddress1
},
],
walletPassphrase: walletPassphrase
});
const explanation = basecoin.explainTransaction({ txHex: transaction.tx });
console.log(transaction.tx);
})();
i am not able to send xrp token. show error below
Unhandled rejection Error: Cannot read property 'nonNumericString' of undefined requestId=cjjs6t6242xd1p9rx1h5u9lch

You have to modify your amount to valid string. Amount '8000.0' is not accepted by bitgo, and you have to remove the fraction part of the string. So the valid amount is '8000'.

Related

tronWeb getAccount returns null

(async function () {
const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider('https://api.trongrid.io');
const solidityNode = new HttpProvider('https://api.trongrid.io');
const eventServer = 'https://api.trongrid.io/';
const privateKey = "04EE63599802B5D31A29C95CC7DF04F427E8F0A124BED9333F3A80404ACFC3127659C540D0162DEDB81AC5F74B2DEB4962656EFE112B252E54AC3BA1207CD1FB1004EE63599802B5D31A29C95CC7DF04F427E8F0A124BED9333F3A80404ACFC3127659C540D0162DEDB81AC5F74B2DEB4962656EFE112B252E54AC3BA1207CD1FB10";
const apiKey ='92959baa-2df2-4292-8309-d87ef88a56d6';
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey)
tronWeb.setHeader({"TRON-PRO-API-KEY": '92959baa-xxx-4292-xxx-d87xxa56d6'});
const newAccount = await tronWeb.createAccount();
//return {
privateKey: 'xxxxxxxxx',
publicKey: 'xxxxxxxxxx',
address: {
base58: 'TURYhSKCw3m84MaKmYhoYqd72ULHRn5zJy',
hex: '41CA6D8549A64DA49324248140789B5A4F52EB022B'
}
}
const account = await tronWeb.trx.getAccount('TURYhSKCw3m84MaKmYhoYqd72ULHRn5zJy');
console.log(account) // returns null object {}
})()
if i try tronWeb.trx.getAccount function it returns null, i asked CHATGPT it said possible this wallet hasnt any transaction that why it returns null,
but i deposited 5 usdt to "TX5pWLD2LbaUaF56L4w7Pqwtg2Wp7eKDZ3" this wallet created by tronWeb.createAccount() when i try request i am getting same action.
uys what is the problem any body can solve this?
i am trying create some wallets TRC20 USDT deposit,transactions etc..
(i used tronweb#4.4 and tronweb#3.2 given same null object result)

DiscordAPIError[50035]: Invalid Form Body data.content[BASE_TYPE_MAX_LENGTH]: Must be 2000 or fewer in length

I Have the Data I Pulled from the Internet via Node js in My Bot
I wanted to share, but I get max_lenght error because the text is too long, what should I do?
the code i wrote;
const interactionCreate = require("../events/interactionCreate");
const Parser = require('rss-parser');
const { SlashCommandBuilder } = require("discord.js");
const parser = new Parser()
const { Routes } = require('discord-api-types/v9')
const { request } = require('undici')
const { EmbedBuilder } = require('discord.js');
const fs = require("fs")
const jsonToTxt = require("json-to-txt");
module.exports = {
name: "adsoyad",
description: "ad soyad bilgi ",
options:[
{
name: "adı",
description: "sorgulanacak kişi ismi",
type: 3,
required: true,
},
{
name: "soyadı",
description : "sorgulanacak kişi soyadı",
type: 3,
required: true,
}
],
run: async (client, interaction) =>{
//const ad = interaction.options.getString("ad");
// const soyad = interaction.options.getString("soyad");
//const feed = await parser.parseURL(`[URL]http://141.11.127.168/ucretsizapi/adsoyad.php?ad=&soyad=sezer&auth=propenthia[/URL]`)
const ad = interaction.options.getString('adı');
const soyad = interaction.options.getString('soyadı');
const query = new URLSearchParams({ ad });
const query2 = new URLSearchParams({ soyad });
const dictResult = await request(`http://141.11.127.168/ucretsizapi/adsoyad.php?${query}&${query2}&auth=propenthia`);
//const list = await dictResult.body.text();
const asa = await dictResult.body.text(8000);
//fs.writeFileSync("data.json", JSON.stringify(asa));
// Convert the JSON data to a text file
//jsonToTxt("data.json", "data.txt");
interaction.length = 8000
//fs.writeFileSync(asa)
await interaction.reply(`${asa}`)
//const ms = await JSON.stringify(list)
//var mars = JSON.parse(ms)
}
}
the error i got;
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError\[50035\]: Invalid Form Body
data.content\[BASE_TYPE_MAX_LENGTH\]: Must be 2000 or fewer in length.
at SequentialHandler.runRequest (C:\\Users\\trwor\\OneDrive\\Masaüstü\\%64 bot Project\\node_modules\\#discordjs\\rest\\dist\\index.js:667:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (C:\\Users\\trwor\\OneDrive\\Masaüstü\\%64 bot Project\\node_modules\\#discordjs\\rest\\dist\\index.js:464:14)
at async REST.request (C:\\Users\\trwor\\OneDrive\\Masaüstü\\%64 bot Project\\node_modules\\#discordjs\\rest\\dist\\index.js:910:22)
at async ChatInputCommandInteraction.reply (C:\\Users\\trwor\\OneDrive\\Masaüstü\\%64 bot Project\\node_modules\\discord.js\\src\\structures\\interfaces\\InteractionResponses.js:111:5)
at async Object.run (C:\\Users\\trwor\\OneDrive\\Masaüstü\\%64 bot Project\\commands\\adsoyad.js:64:9) {
requestBody: {
I need your help my friends, thank you in advance to those who try to solve it, frankly, I had a very difficult time.

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Objec

I want to convert the data taken from the internet on a node js to json file and convert it to txt, but I get an error
const interactionCreate = require("../events/interactionCreate");
const Parser = require('rss-parser');
const { SlashCommandBuilder } = require("discord.js");
const parser = new Parser()
const { Routes } = require('discord-api-types/v9')
const { request } = require('undici')
const { EmbedBuilder } = require('discord.js');
const fs = require("fs")
const jsonToTxt = require("json-to-txt");
module.exports = {
name: "adsoyad",
description: "ad soyad bilgi ",
options:[
{
name: "adı",
description: "sorgulanacak kişi ismi",
type: 3,
required: true,
},
{
name: "soyadı",
description : "sorgulanacak kişi soyadı",
type: 3,
required: true,
}
],
run: async (client, interaction) =>{
//const ad = interaction.options.getString("ad");
// const soyad = interaction.options.getString("soyad");
//const feed = await parser.parseURL(`[URL]http://141.11.127.168/ucretsizapi/adsoyad.php?ad=&soyad=sezer&auth=propenthia[/URL]`)
const ad = interaction.options.getString('adı');
const soyad = interaction.options.getString('soyadı');
const query = new URLSearchParams({ ad });
const query2 = new URLSearchParams({ soyad });
const dictResult = await request(`http://141.11.127.168/ucretsizapi/adsoyad.php?${query}&${query2}&auth=propenthia`);
//const list = await dictResult.body.text();
const asa = await dictResult.body.json();
const dataInString = jsonToTxt({ filePath: asa });
await interaction.reply("sonuclar")
//const ms = await JSON.stringify(list)
//var mars = JSON.parse(ms)
}
}
When I enter the command in Discord, I want it to be sent as txt.
the error i got;
The error I get when I try to translate
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object
at Object.open (node:fs:561:10)
at Object.writeFile (node:fs:2185:6)
at Object.run (C:\Users\trwor\OneDrive\Masaüstü\%64 bot Project\commands\adsoyad.js:53:12)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Object
at Object.openSync (node:fs:592:10)
at Object.readFileSync (node:fs:468:35)
at getData (C:\Users\trwor\OneDrive\Masaüstü\%64 bot Project\node_modules\json-to-txt\src\lib.js:63:26)
at main (C:\Users\trwor\OneDrive\Masaüstü\%64 bot Project\node_modules\json-to-txt\json_to_txt.js:5:16)
at Object.run (C:\Users\trwor\OneDrive\Masaüstü\%64 bot Project\commands\adsoyad.js:53:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
I want to solve my problem fast
Thank you in advance to those who are interested.
I actually want to take json and convert it to txt. I want to specify the txty I translated
Based on the error message, it looks like the argument passed to jsonToTxt is an object, but it is expected to be a file path string or a buffer. To solve the issue, you need to provide a valid file path string to jsonToTxt instead of the JSON data itself.
U need the JSON data to write data to a file, then converts it to a text file:
const interactionCreate = require("../events/interactionCreate");
const Parser = require('rss-parser');
const { SlashCommandBuilder } = require("discord.js");
const parser = new Parser()
const { Routes } = require('discord-api-types/v9')
const { request } = require('undici')
const { EmbedBuilder } = require('discord.js');
const fs = require("fs")
const jsonToTxt = require("json-to-txt");
module.exports = {
name: "adsoyad",
description: "ad soyad bilgi ",
options:[
{
name: "adı",
description: "sorgulanacak kişi ismi",
type: 3,
required: true,
},
{
name: "soyadı",
description : "sorgulanacak kişi soyadı",
type: 3,
required: true,
}
],
run: async (client, interaction) =>{
//const ad = interaction.options.getString("ad");
// const soyad = interaction.options.getString("soyad");
//const feed = await parser.parseURL(`[URL]http://141.11.127.168/ucretsizapi/adsoyad.php?ad=&soyad=sezer&auth=propenthia[/URL]`)
const ad = interaction.options.getString('adı');
const soyad = interaction.options.getString('soyadı');
const query = new URLSearchParams({ ad });
const query2 = new URLSearchParams({ soyad });
const dictResult = await request(`http://141.11.127.168/ucretsizapi/adsoyad.php?${query}&${query2}&auth=propenthia`);
//const list = await dictResult.body.text();
const asa = await dictResult.body.json();
// Write the JSON data to a file
fs.writeFileSync("data.json", JSON.stringify(asa));
// Convert the JSON data to a text file
jsonToTxt("data.json", "data.txt");
await interaction.reply("sonuclar")
}
}

UniswapV2 swapExactETHForTokens method fails with error status 'UniswapV2: TRANSFER_FAILED'

I am using web3.js library and I am trying to buy a token by calling swapExactETHForTokens method from
UniswapV2Router02 smart contract, but I don't know why my transaction fails. I approved WETH for this transaction, but still get an error with the following status:
Fail with error 'UniswapV2: TRANSFER_FAILED'
My code:
const swapTokens = async () => {
const PRIVATE_KEY = 'my private key goes here';
web3.eth.accounts.wallet.add(PRIVATE_KEY);
const myAccount = web3.eth.accounts.wallet[0].address;
const WETHAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const swapRouterAddress = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
const routerContract = new web3.eth.Contract(
UNISWAP_V2_ROUTER_ABI,
swapRouterAddress,
);
const tokenToBuyAddress = '0x0913dDAE242839f8995c0375493f9a1A3Bddc977';
const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
const block = await web3.eth.getBlock('latest');
const gasLimit = Math.round(block.gasLimit / block.transactions.length);
const amountToBuy = 0.01;
const result = await routerContract.methods
.swapExactETHForTokens(
web3.utils.toHex(0),
[WETHAddress, tokenToBuyAddress],
myAccount,
deadline,
)
.send({
from: myAccount,
gasLimit,
value: web3.utils.toWei(`${amountToBuy}`, 'ether'),
});
console.log('result: ', result);
}
swapTokens();
Transaction details on etherscan: https://etherscan.io/tx/0x4c6f507ed95b2889bdb929a34dbbe0114db168c2462ce21778eeed9dc4a894eb
Smart contract of token which I am trying to buy: https://etherscan.io/address/0x0913dDAE242839f8995c0375493f9a1A3Bddc977#code
Your transaction ran out of gas. Increase your gas limit

Trying to send the ltc coin uisng Bitgo js

I want to send the ltc using bitGo js api, but its not wokring there is issue of the amount.It works well for btc but not for ltc.I have tried to covert the amount into satoshi and litoshi but till it not working.Following is my code:
const BitGoJS = require('../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const coin = 'tltc';
const basecoin = bitgo.coin(coin);
// TODO: set your access token here
const accessToken = null;
const walletId = '5941ce2db42fcbc70717e5a898fd1595';
// TODO: set your passphrase here
const walletPassphrase = null;
Promise.coroutine(function *() {
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
const walletInstance = yield basecoin.wallets().get({ id: walletId });
const newReceiveAddress1 = yield walletInstance.createAddress();
const newReceiveAddress2 = yield walletInstance.createAddress();
const transaction = yield walletInstance.sendMany({
recipients: [
{
amount: '12341234', //not getting how to convert the amount here
address: newReceiveAddress1.address
},
],
walletPassphrase: walletPassphrase
});
const explanation = basecoin.explainTransaction({ txHex: transaction.tx });
console.log('Wallet ID:', walletInstance.id());
console.log('Current Receive Address:', walletInstance.receiveAddress());
console.log('New Transaction:', JSON.stringify(transaction, null, 4));
console.log('Transaction Explanation:', JSON.stringify(explanation, null, 4));
})();
Please suggest some solution how to resolve the amount issue while passing to the api for send method in bitGo js

Resources