tatumio/tatum-csharp

Create Private Key for One BTC address failed with Rest Client, but works with Node.js

Closed this issue · 1 comments

Hello:
I read the Tatum documents, and I tried to use C# later on to do some testing. I use Rest Client - Insomnia, which can generate HTTP requests, so I can see the HTTP requests, then I can use the C# code generated by Insomnia to write the code, it is better than writing C# code from the very beginning.
Following the documents, I can use HTTP requests to create one BTC wallet, one BTC wallet address. But when I tried to create a private key for the generated BTC address, I got the following errors:
{
"statusCode": 400,
"errorCode": "validation.failed",
"message": "Request validation failed. Please see data for additional information.",
"data": [
"Mnemonics must consist of 12 or 24 words, and every word should be at least 2 letters long.",
"mnemonic must be shorter than or equal to 500 characters",
"mnemonic should not be empty",
"index must not be greater than 2147483647",
"index must not be less than 0",
"index must be an integer number",
"index should not be empty"
]
}
I used the Mnemonics when I created BTC wallet, I don't think it is wrong.
The following is the payload for HTTP POST request:
{
"mnemonic": "My_24_Words_Long_Paraphrase",
"index": 1
}
However, since I know some Node.js, so I wrote the following node.js (ver 19.1.0) script:
const Tatum = require('@tatumio/tatum');
const {generatePrivateKeyFromMnemonic, Currency} = require("@tatumio/tatum");

const CreatePrivateKey = async () =>
{
try
{
const btcPrivateKey =
await generatePrivateKeyFromMnemonic(Currency.BTC, false, "My_24_Words_Long_Paraphrase", 1);
console.log({key: btcPrivateKey});}
catch (err)
{
console.log(err);
}
};
CreatePrivateKey();
And this Node.JS script works.
Please advise on what could be the issue for using Rest Client - Insomnia to generate a private key for the address I created. But for Node.JS, my code works.
Thanks,

Hello @zydjohnHotmail,
Can we please move the discussion to https://discord.com/channels/847940290903932939/914832388431958036

I'll be able to answer all of your questions related to use cases there. Github issues it more for technical issues with the SDKs and not so well suited for support discussions.

As for the question you have two option to generate wallets within the SDK. No need to use any other HttpClient. Please take a look here https://github.com/tatumio/tatum-csharp/blob/master/Tatum.CSharp.Demo/ExampleServices/Bitcoin/GenerateWalletExampleService.cs

You can also achive that by calling Tatum endpoint via SDK like this _bitcoinClient.BitcoinBlockchain.GenerateWallet()
but it's recommend to generate wallets locally like in the example file to prevent your secrets from going around through the network.