fyziktom / VirtualEconomyFramework

Framework for economy applications
https://veframework.com/
MIT License
24 stars 7 forks source link

Add helper function for IssueToken API command #149

Open fyziktom opened 2 years ago

fyziktom commented 2 years ago

The Neblio allows to issue own tokens for specific purpose. The VEDriversLite wraps this API command, but do not offer any helper class which can make easier to go through whole procedure. We should add some helper command which will simplify it.

Actual example can be like this: These are some example parameters for issue the token (just change the name, etc.):

{
  "issueAddress": "NeEHHAWBAgCQKH8hfaXgRZUTiJaF9a3pH1",
  "amount": 1000000000000000,
  "divisibility": 7,
  "fee": 1000000000,
  "reissuable": false,
  "flags": {
    "splitChange": true
  },
  "metadata": {
    "tokenName": "BDPT",
    "issuer": "fyziktom",
    "description": "BaseDataPlaceToken",
    "userData": {
      "urls": [
      {
        "name": "BDPT",
        "url": "https://ipfs.infura.io/ipfs/QmYMVuotTTpW24eJftpbUFgK7Ln8B4ox3ydbKCB6gaVwVB",
        "mimeType": "png",
        "dataHash": ""
      }
      ],
      "meta": [
        {
          "key": "BDPT",
          "value": "Test of issue API"
        }
      ]
    }
  }
}

When you send this to the Neblio API (you can test it here ). You will receive raw hex of transaction which require to be signed and broadcast. Then you can use this sequence of the code:

            //the "hex" tx from Neblio API IssueToken response
            var tx = "010000002783e062013f50df796c3dee91ab7a4a9661e3d0e5258d98a9118493e60dd6e5053d28b7fb0000000000ffffffff031027000000000000f36a4cf04e5403014244505420201f00f0000000df789c558fd14ac43010457fa5ccb36c411795be598ba8ab52215664f121bb9d7443db246412b596febb9345101fefe5cec9c90cad0c128a1982edd13cc911a180b2aa059c80268ae839abe95bf7c18edcb5487baf5dd0d6a4a124ac18500f728f22117812097df54b8d7e2028b633987f64ae391c427054e4b9768a56daa8e8e54adb63cc9fc7b7c726da20847b3d5de3bd0a6ef772d36d2e1ecc65b9b65f6753bbdb5c97e79d6c3e9b9291a31e514c2e3de24c974c59e156d2810b58de79804989557a9cfe4c3ee410d38d400a9955d9f1cfd9557dc737cbb2fc005ad65f49e092f505000000001976a914c8e8dadb3bde0ecb186aacfb5d437db62fb89a6888ac10270000000000001976a914c8e8dadb3bde0ecb186aacfb5d437db62fb89a6888ac00000000";

            // this is just to obtain proper private key for this transaction example...
            var acccntfile = "Backup-Export.txt";
            var acccnt = new NeblioAccount();
            await acccnt.LoadAccountFromVENFTBackup("YOUR_PASSWORD_FOR_BACKUP_FILE", "", acccntfile);

            // parse raw hex to NBitcoin transaction object
            if (!Transaction.TryParse(tx, NeblioTransactionHelpers.Network, out var transaction))
            {
                throw new Exception("Cannot parse token tx raw hex.");
            }
            //call the sign of the transaction and broadcast
            var result = await NeblioTransactionHelpers.SignAndBroadcastTransaction(transaction, acccnt.Secret);