Facebook
From Ivory Treeshrew, 1 Week ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 27
  1.   async _spendToAddress(amount, address) {
  2.     const mtx = new MTX();
  3.     const utxo = await this._getUnspentOutput(amount);
  4.     const change = await this._allocateSlot();
  5.  
  6.     if (!this._state.coins.length) throw new Error('No available funds.');
  7.  
  8.     mtx.addOutput({
  9.       address: address,
  10.       value: amount
  11.     });
  12.  
  13.     await mtx.fund(this._state.coins, {
  14.       rate: 10,
  15.       changeAddress: change.string
  16.     });
  17.  
  18.     mtx.sign(this.ring);
  19.  
  20.     const tx = mtx.toTX();
  21.     const valid = tx.verify(mtx.view);
  22.     console.log('is valid:', valid);
  23.  
  24.     return tx;
  25.   }