MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.87k stars 848 forks source link

Bitcoins not appearing #296

Closed earamsey closed 6 years ago

earamsey commented 6 years ago

I sent myself $1.20 USD from a proven bitcoinj wallet. But the transaction is not appearing. The BitcoinJ client is using network.main. The NBitcoin SPVSample is your sample wallet I am trying to send to.

NicolasDorier commented 6 years ago

hey, even after the transaction got confirmed ?

earamsey commented 6 years ago

yes it is confirmed still not arriving

On Sat, Oct 28, 2017 at 10:58 PM, Nicolas Dorier notifications@github.com wrote:

hey, even after the transaction got confirmed ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-340235922, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu6glyHoXLl5U1F74iZaX-uqwlAwoks5sw_ffgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

earamsey commented 6 years ago

I generated a new wallet and sent coins to it and it received it. Is there a way to recover wallet so I can get those coins?

On Sun, Oct 29, 2017 at 7:56 AM, Erica Ramsey erica.ramsey@gmail.com wrote:

yes it is confirmed still not arriving

On Sat, Oct 28, 2017 at 10:58 PM, Nicolas Dorier <notifications@github.com

wrote:

hey, even after the transaction got confirmed ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-340235922, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu6glyHoXLl5U1F74iZaX-uqwlAwoks5sw_ffgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~ erica.ramsey/cv/index.htm

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

Yes, you can surely recover it. My SPVSample is kind of old, and SPV not much used outside of breadwallet. One possible issue is that the peer you connected to did not told you about the transaction despite you asking for it. A bug might be possible as well though, hard to say.

Anyway, you can get it back. Update to NBitcoin 4.0.0.39 (last version I did). I added Wallet.Rescan(blockId). Once the chain is synched, call this method with a block before your payment got confirmed (be sure it returns true).

nopara73 commented 6 years ago

@earamsey If you are interested in SPV sample in C#, you can look at HiddenWallet or Breeze Wallet/

NicolasDorier commented 6 years ago

@earamsey HiddenWallet or Breeze Wallet are probably more tested than NBitcoin SPV, I think it is indeed wise for you to take a look there.

earamsey commented 6 years ago

Ok, I'm stuck. trying to use NBitcoin to send back coins I sent to myself. Can you see what I am doing wrong? var mbwallet = (root.DataContext as MBWallet); var wallet = mbwallet.Wallet;

        var otheraddress =

BitcoinAddress.Create("zzzzzxDQTmTsBgxxxxxWJbuNGCwZxhiM8", Network.Main); // address I want to send to var myaddress = mbwallet.CurrentAddress; // my bitcoin address var txout = mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First(); // First Transaction 0.0007 value var money = txout.Value; // 0.0007 Transaction myFunding = new Transaction() { Outputs = {

//mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First() new TxOut(money, myaddress), } }; Coin[] myCoins = myFunding .Outputs .Select((o, i) => new Coin(new OutPoint(myFunding.GetHash(), i), o)) .ToArray(); var txBuilder = new TransactionBuilder(); var tx = txBuilder .AddCoins(myCoins) .AddKeys(mbwallet.PrivateKeys) .Send(otheraddress, "0.0005") .SendFees("0.0001") .SetChange(myaddress) // I should get back 0.0001 .BuildTransaction(true); var txrep = new QBitNinjaTransactionRepository(App.Network); txrep.Put(tx.GetHash(), tx); var client = new QBitNinjaClient(App.Network); BroadcastResponse broadcastResponse = client.Broadcast(transaction).Result;

broadcastResponse.Success == true broadcastResponse .Error.ErrorCode == INVALID broadcastResponse .Error.Reason == "Unkown"

The transaction never appears on network. Any help appreciated!

On Sat, Oct 28, 2017 at 10:58 PM, Nicolas Dorier notifications@github.com wrote:

hey, even after the transaction got confirmed ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-340235922, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu6glyHoXLl5U1F74iZaX-uqwlAwoks5sw_ffgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

ok so this bug might come from QBitNinja. The broadcast does not always work... I will fix that later. But to be sure it is the cause, print tx.ToHex() and try to broadcast manually on https://www.smartbit.com.au/txs/pushtx

nopara73 commented 6 years ago

@earamsey You can use my SmartBitClient. Look at PushTransactionAsync.

NicolasDorier commented 6 years ago

@nopara73 possible that it does not work... Unity seems to not support https with HttpClient.

nopara73 commented 6 years ago

If so, check out BlockcypherClient and implement pushtransaction: https://www.blockcypher.com/dev/bitcoin/#push-raw-transaction-endpoint

HTTP on smartbit does not work: http://api.smartbit.com.au/v1/exchange-rates

earamsey commented 6 years ago

using that site I get; PUSH TRANSACTION ERROR: MISSING INPUTS and I used TransactionBuilder to create it; var mbwallet = (root.DataContext as MBWallet); var wallet = mbwallet.Wallet;

        var otheraddress =

BitcoinAddress.Create("1kdUxDQTmTsBg734i7gWJbuNGCwZxhiM8", Network.Main); var myaddress = mbwallet.CurrentAddress; var txout = mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First(); var money = txout.Value; Transaction myFunding = new Transaction() { Outputs = {

//mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First() new TxOut(money, mbwallet.CurrentAddress), },

        };
        Coin[] myCoins = myFunding
                            .Outputs
                            .Select((o, i) => new Coin(new

OutPoint(myFunding.GetHash(), i), o)) .ToArray(); var txBuilder = new TransactionBuilder(); var tx = txBuilder .AddCoins(myCoins) .AddKeys(mbwallet.PrivateKeys) .Send(otheraddress, "0.0005") .SendFees("0.0001") .SetChange(myaddress) .BuildTransaction(true); Not sure what is wrong. mbwallet.PrivateKeys is created using; PrivateKeys = File.ReadAllText(PrivateKeyFile) .Split(',') .Select(c => new BitcoinExtKey(c, App.Network)) .ToArray(); following your code example. I am lost.

On Thu, Nov 9, 2017 at 9:42 PM, Nicolas Dorier notifications@github.com wrote:

ok so this bug might come from QBitNinja. The broadcast does not always work... I will fix that later. But to be sure it is the cause, print tx.ToHex() and try to broadcast manually on https://www.smartbit.com.au/txs/pushtx

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-343366579, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu1IhN6ic4lI-BQgetULXqnfnv-Bgks5s08YqgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

nopara73 commented 6 years ago

Fixed That For You :)

Using that site I get: PUSH TRANSACTION ERROR: MISSING INPUTS, and I used the TransactionBuilder to create it:

 var mbwallet = (root.DataContext as MBWallet);
            var wallet = mbwallet.Wallet;

            var otheraddress =
BitcoinAddress.Create("1kdUxDQTmTsBg734i7gWJbuNGCwZxhiM8", Network.Main);
            var myaddress = mbwallet.CurrentAddress;
            var txout =
mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First();
            var money = txout.Value;
            Transaction myFunding = new Transaction()
            {
                Outputs =
                {

//mbwallet.Transactions[0]._Transaction.Transaction.Outputs.First()
                    new TxOut(money, mbwallet.CurrentAddress),
                },

            };
            Coin[] myCoins = myFunding
                                .Outputs
                                .Select((o, i) => new Coin(new
OutPoint(myFunding.GetHash(), i), o))
                                .ToArray();
            var txBuilder = new TransactionBuilder();
            var tx = txBuilder
                .AddCoins(myCoins)
                .AddKeys(mbwallet.PrivateKeys)
                .Send(otheraddress, "0.0005")
                .SendFees("0.0001")
                .SetChange(myaddress)
                .BuildTransaction(true);

Not sure what is wrong. mbwallet.PrivateKeys is created using:

 PrivateKeys =
                    File.ReadAllText(PrivateKeyFile)
                    .Split(',')
                    .Select(c => new BitcoinExtKey(c, App.Network))
                    .ToArray();

Following your code example. I am lost.

nopara73 commented 6 years ago

@earamsey I'm not sure I hundred percent understand your code. Could you reproduce it on the testnet, so you can give out more information about the actual transactions you want to spend?

earamsey commented 6 years ago

ok, but even better would you happen to have example of sending transaction? I'm am trying to spend a bitcoin?

On Sat, Nov 11, 2017 at 3:20 PM, nopara73 notifications@github.com wrote:

@earamsey https://github.com/earamsey I'm not sure I hundred percent understand your code. Could you reproduce it on the testnet, so you can give out more information about the actual transactions you want to spend?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-343694930, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbuwwbzRRHqfDavKFlYzXI0HcUDiO6ks5s1g-HgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

nopara73 commented 6 years ago

@earamsey Yes: https://github.com/nopara73/HiddenWallet/blob/master/HiddenWallet.FullSpvWallet/WalletJob.cs#L893-L1085

earamsey commented 6 years ago

Hi, I am finally able to send bitcoins with NBitcoin. Now I want to more accurately compute the fee. Does "Transaction.GetVirtualSize()" return bytes per transaction? To compute fee I use; var transactionFee = new Money(Fee * transaction.GetVirtualSize(), MoneyUnit.Satoshi);

I get Fee from https://bitcoinfees.earn.com/api/v1/fees/recommended which returns current rate of "satoshis per byte". Currently, this value is 400 satoshis per byte. So, you see why I need to know what transaction.GetVirtualSize() returns. By the way, does my fee computation look ok?

Thanks for the help!

On Sun, Oct 29, 2017 at 7:56 AM, Erica Ramsey erica.ramsey@gmail.com wrote:

yes it is confirmed still not arriving

On Sat, Oct 28, 2017 at 10:58 PM, Nicolas Dorier <notifications@github.com

wrote:

hey, even after the transaction got confirmed ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-340235922, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu6glyHoXLl5U1F74iZaX-uqwlAwoks5sw_ffgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~ erica.ramsey/cv/index.htm

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

earamsey commented 6 years ago

I ask because when sending i'm getting large fees in my calculation above so I assume is that transaction.GetVirtualSize() is not in bytes.

On Thu, Dec 7, 2017 at 8:21 PM, Erica Ramsey erica.ramsey@gmail.com wrote:

Hi, I am finally able to send bitcoins with NBitcoin. Now I want to more accurately compute the fee. Does "Transaction.GetVirtualSize()" return bytes per transaction? To compute fee I use; var transactionFee = new Money(Fee * transaction.GetVirtualSize(), MoneyUnit.Satoshi);

I get Fee from https://bitcoinfees.earn.com/api/v1/fees/recommended which returns current rate of "satoshis per byte". Currently, this value is 400 satoshis per byte. So, you see why I need to know what transaction.GetVirtualSize() returns. By the way, does my fee computation look ok?

Thanks for the help!

On Sun, Oct 29, 2017 at 7:56 AM, Erica Ramsey erica.ramsey@gmail.com wrote:

yes it is confirmed still not arriving

On Sat, Oct 28, 2017 at 10:58 PM, Nicolas Dorier < notifications@github.com> wrote:

hey, even after the transaction got confirmed ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-340235922, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu6glyHoXLl5U1F74iZaX-uqwlAwoks5sw_ffgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica .ramsey/cv/index.htm

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~ erica.ramsey/cv/index.htm

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

if you use the TransactionBuilder you don't have to use GetVirtualSize() use TransactionBuilder.SendEstimatedFees.

earamsey commented 6 years ago

I will try to use that, in case that doesn't work out for me does GetVirtualSize() returns size in bytes for transaction?

On Thu, Dec 7, 2017 at 11:10 PM, Nicolas Dorier notifications@github.com wrote:

if you use the TransactionBuilder you don't have to use GetVirtualSize() use TransactionBuilder.SendEstimatedFees.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-350173924, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu7lY1Em95rauXD80yKEchsKillDEks5s-MSzgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

GetVirtualSize() sends you back the amount of byte you should use for fee calculations. (Discounting witness bytes)

Don't do it by yourself, this is very hard. Because if you do GetVirtualSize() on an unsigned transaction you won't get the right size, because signatures are not included. But if you do it after signing, then you can't modify the fees anymore without breaking the signature. TransactionBuilder is doing it the optimal way, and hide the messiness. (It does so by building a dummy transaction with fake signatures, calculating the fees, then rebuilding with real signature)

earamsey commented 6 years ago

Hi, TransactionBuilder.SendEstimatedFees takes a FeeRate I pass in the value from https://bitcoinfees.earn.com/api/v1/fees/recommended into FeeRate after adjusting to kilo?

I want to display the Fee to user before they send the transaction that is why I am in this mess. So to use TransactionBuilder to show fee I must; 1.Modify NBitcoin.TransactionBuilder to make _TotalFee accessible to my app. 2.Everytime send amount changes use TransactionBuilder to recomputed fee with SendEstimatedFees grab the value from TransactionBuilder._TotalFee and display to user.

Sounds about right or is it totally wrong or just bad idea?

On Fri, Dec 8, 2017 at 9:24 PM, Nicolas Dorier notifications@github.com wrote:

GetVirtualSize() sends you back the amount of byte you should use for fee calculations. (Discounting witness bytes)

Don't do it by yourself, this is very hard. Because if you do GetVirtualSize() on an unsigned transaction you won't get the right size, because signatures are not included. But if you do it after signing, then you can't modify the fees anymore without breaking the signature. TransactionBuilder is doing it the optimal way, and hide the messiness.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-350420348, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu41o4TN_vfWuBuBoNXa1aib8wKJkks5s-f2CgaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

@earamsey once you have the signed transaction you can get the actual fees with:

var fee = tx.GetFee(txBuilder.FindSpentCoins(tx));
earamsey commented 6 years ago

Hi, thanks for your help! I have final code I think.

// sendAmount -- the amount we want to send // send fee gathered from https://bitcoinfees.earn.com/api/v1/fees/recommended public static decimal ComputeSendFee(decimal sendAmount, decimal sendFee) { var tempDestination = new Key().GetWif(App.Network).GetAddress(); // fake address for computing fee var feePerTransaction = new Money(Convert.ToInt32((sendFee)), MoneyUnit.Satoshi); var builder = new TransactionBuilder(); try { var coins = GetCoins(sendAmount); builder.AddCoins(coins) .AddKeys(MBWallet.Wallet.BitcoinPrivateKey) .SetChange(MBWallet.Wallet.Address) .Send(tempDestination, new Money(sendAmount, MoneyUnit.BTC)) .SendEstimatedFees(new FeeRate(feePerTransaction)); break; } catch (NotEnoughFundsException e) { throw e; } var tx = builder.BuildTransaction(true); // generate transaction and sign var txFee = tx.GetFee(builder.FindSpentCoins(tx)); return txFee.ToDecimal(MoneyUnit.BTC); } private static List GetCoins(decimal sendAmount) { var amountMoney = new Money(sendAmount, MoneyUnit.BTC); var client = new QBitNinjaClient(App.Network); var txInAmount = Money.Zero; var coins = new List(); foreach (var balance in client.GetBalance(MBWallet.Wallet.Address, true).Result.Operations) { var transactionId = balance.TransactionId; var transactionResponse = client.GetTransaction(transactionId).Result; var receivedCoins = transactionResponse.ReceivedCoins; foreach (Coin coin in receivedCoins) { if (coin.TxOut.ScriptPubKey == MBWallet.Wallet.BitcoinPrivateKey.ScriptPubKey) // this may not be necessary { coins.Add(coin); txInAmount += (coin.Amount as Money); } } } return coins; }

It computes fee for send amount of "0.00001" (0.15USD) as "0.00001076" (0.16USD). However, for send amount of "0.0001" (1.49USD) it computes fee of "0.0000009" (0.01USD). Is this normal?

On Sat, Dec 9, 2017 at 10:27 PM, Nicolas Dorier notifications@github.com wrote:

@earamsey https://github.com/earamsey once you have the signed transaction you can get the fees with:

var fee = tx.GetFee(txBuilder.FindSpentCoins(tx));

b

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MetacoSA/NBitcoin/issues/296#issuecomment-350524412, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpbu8fq3vPQjIeIi11jSHixuW2fcCEsks5s-12ggaJpZM4QKJRG .

-- Thanks,

Erica A Ramsey Software Engineering Mobile Application Developer Resume ~ (see link below) Some Project Screenshots ~ http://home.comcast.net/~erica.ramsey/cv/index.htm

NicolasDorier commented 6 years ago

The amount of fees depends on the size of the transaction which depends on which Coins has been selected. So yes this is normal.

It is possible that the estimated fee rate be a bit different from the actual one, but normally no more than 2% difference.

You can check the actual rate used like that:

var actualFeeRate = new FeeRate(txFee, tx.GetVirtualSize());
NicolasDorier commented 6 years ago

Closing for inactivity, reopen if needed.

compilenewbe commented 6 years ago

I've been trying to follow this to run the txBuilder, when i got the Hex and put it on the web page, i got PUSH TRANSACTION ERROR: MISSING INPUTS, I think because of the format of the private key, but i am not sure of that, what other stuff should be causing this problem? btw, I am using the same logic as @earamsey TransactionBuilder txBuilder = new TransactionBuilder(); var tx = txBuilder .AddCoins(myFunding) .AddKeys(mbwallet.SelectedWallet.PrivateKeys) .Send(otheraddress, value) .SendFees("0.001") .SetChange(mbwallet.SelectedWallet.CurrentAddress) .BuildTransaction(true); Console.WriteLine(txBuilder.Verify(tx)); tx.ToHex();

NicolasDorier commented 6 years ago

how do you get myFunding

compilenewbe commented 6 years ago

this is the code i am using,

        string address = Address.Text;
        var destination = BitcoinAddress.Create(address, App.Network);
        string value = Value.Text;

        var mbwallet = (root.DataContext as MainWindowViewModel);

        var key = mbwallet.SelectedWallet.PrivateKeys[0].PrivateKey.GetBitcoinSecret(App.Network).ToString();
        BitcoinSecret privkey = new BitcoinSecret(key);
        var myaddress = privkey.PubKey.GetAddress(App.Network);

        var txout = mbwallet.SelectedWallet.Transactions[0]._Transaction.Transaction.Outputs.First();
        var money = txout.Value;

        Transaction myFunding = new Transaction()
        {
            Outputs =
            {
                new TxOut(money, myaddress),
            }
        };
        Coin[] allcoins = myFunding
                            .Outputs
                            .Select((o, i) => new Coin(new OutPoint(myFunding.GetHash(), i), o))
                            .ToArray();

        TransactionBuilder txBuilder = new TransactionBuilder();
        var tx = txBuilder
            .AddCoins(allcoins)
            .AddKeys(privkey)
            .Send(destination, value)
            .SendFees("0.01")
            .SetChange(myaddress)
            .BuildTransaction(true);
        Console.WriteLine(txBuilder.Verify(tx));

        var hello = tx.ToHex();

        var client = new QBitNinjaClient(Network.TestNet);
        BroadcastResponse broadcastResponse = client.Broadcast(tx).Result;

i have a doubt and is that if that mbwallet, that @earamsey created is new or is an object already created?

NicolasDorier commented 6 years ago

myFunding does not exist on the blockchain. txBuilder.Verify only verify that this tx is correctly signed, not that the inputs are unspent.

compilenewbe commented 6 years ago

I have a problem with private keys, i need a secret key to sign the transaction, but i dont know how to convert the EtPrivKey that the program creates, to a small private key,

//var extprivkey = new BitcoinExtKey("tprv8ZgxMBicQKsPdyamkZnBjh8kG4kW6ZAtzkonTCeeNCuWMH5K2jqJAMac1rwct3iG1ygu4tM8Zh1jnQVAh2hGMAEUXATmj48JpeP3J3z42Wt");

        //var extkey = mbwallet.SelectedWallet.PrivateKeys[0].ToWif();
        //var extkeyy = new BitcoinExtKey(extkey);
        //var alt = Key.Parse(extkey, App.Network);
        //var pri = new BitcoinSecret(alt, App.Network);
        //BitcoinSecret record = extkeyy.PrivateKey.GetBitcoinSecret(App.Network);
        //var addressss = record.GetAddress();
        var key = mbwallet.SelectedWallet.PrivateKeys[0].PrivateKey.GetBitcoinSecret(App.Network).ToString();
        var priv = new BitcoinSecret(key);

if i use the variable priv, does not sign the transaction and if i use the extkeyy, throws an error saying it can't use it because it only acepts base58 values.

Is there a way to conver it?