Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change method does not work #3609

Open
Sequoya42 opened this issue Jul 13, 2023 · 0 comments
Open

change method does not work #3609

Sequoya42 opened this issue Jul 13, 2023 · 0 comments

Comments

@Sequoya42
Copy link

Sequoya42 commented Jul 13, 2023

Assuming for example that from contains 1 doge, send 0.5 to to, expect from to end up at 0.5 (minus fees).
All parameters are valid.
Does not work. Rest of the funds are sent to miner.

https://sochain.com/tx/DOGE/35d551e393f5c6822fcd0f0989cce980f75d40824b136f31980e3393810a49a4

Using the following code

  const transactionFee = 2e6; // 0.02 doge

  let tx = new Transaction().fee(transactionFee)
    .from(from.utxos)
    .to(to.address, Math.floor(amount))
    .change(from.address)
    .sign(from.privkey);

Force me to do something like

  let tx = new Transaction().fee(transactionFee)
    .from(from.utxos)
    .to(to.address, Math.floor(amount))
    .to(from.address, balance - amount - transactionFee - taxTransfer)
    .change(from.address)
    .sign(from.privkey);

For it to work.
According to the documentation :

var transaction = new Transaction()
    .from(utxos)          // Feed information about what unspent outputs one can use
    .to(address, amount)  // Add an output with the given amount of satoshis
    .change(address)      // Sets up a change address where the rest of the funds will go
    .sign(privkeySet)     // Signs all the inputs it can
    ```
    
    Change function should send the rest of the fund back to the from address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant