badger-cash / badger

Your gateway to the world of Bitcoin Cash (BCH) apps
https://badger.bitcoin.com/
MIT License
63 stars 47 forks source link

Ability to create SLP create token transactions w/ mint baton per SLP spec #228

Open nickfujita opened 4 years ago

nickfujita commented 4 years ago

What problem are you trying to solve? The current implementation of sendTransaction on web4bch currently allows for the creation of new SLP tokens according to the SLP specifications, as long as there is no mint baton specified. If a mint baton is requested to be issued, it can only appear to be set on the change vout for the remaining BCH from the vin utxos. Since the OP_RETURN is being created before calling sendTransaction, the user can set the mint baton index to any number, but the transaction generated does not allow for multiple outputs, so the only option at the moment appears to be vout2 (the change address).

Describe the solution you'd like In order to add flexibility beyond just creating SLP tokens, it may be an opportunity to enhance the sendTransaction method to allow the user to specify multiple outputs. As a general use case, it would allow users to send BCH to multiple addresses for varying amounts in the same transaction. But more specifically, it will enable the user to specify the appropriate number of utxo outputs to facilitate the creating of SLP tokens with a mint baton to a specific address, and also allow users to back any SLP tokens with any desired amount of BCH.

Here are a couple of examples of what the updated parameters object for sendTransaction could look like:

Send w/ multiple outpus

The following would result in a transaction with 3 utxo outputs.

const txParams = {
  from: web4bch.bch.defaultAccount,
  outputs: [
    {
      address: <bch_address>,
      amount: '12345',
    },
    {
      address: <bch_address>,
      amount: '6789',
    }
  ]
};

SLP create token

The following would result in a transaction with 4 utxo outputs.

const encodedData = slpjs.Slp.buildGenesisOpReturn({
  ticker: <ticker>,
  name: <name>,
  documentUri: <documentUri>,
  hash: <documentHash>,
  decimals: <decimals>,
  batonVout: 2,
  initialQuantity: 10000000000,
});

const txParams = {
  from: web4bch.bch.defaultAccount,
  outputs: [
    {
      address: <bch_address>,
      amount: '546',
    },
    {
      address: <bch_address>,
      amount: '546',
    }
  ],
  opReturn: {
    data: encodedData,
    isEncoded: true,
    position: '0',
  },
};

Additional context SLP token genesis transaction spec