Exemplo n.º 1
0
        public static Transaction SendAsset(NeoAPI neoAPI, KeyPair fromKey, string toAddress, string symbol, decimal amount)
        {
            if (String.Equals(fromKey.address, toAddress, StringComparison.OrdinalIgnoreCase))
            {
                throw new NeoException("Source and dest addresses are the same");
            }

            var toScriptHash = toAddress.GetScriptHashFromAddress();
            var target       = new Transaction.Output()
            {
                scriptHash = new UInt160(toScriptHash), value = amount
            };
            var targets = new List <Transaction.Output>()
            {
                target
            };

            List <Transaction.Input>  inputs;
            List <Transaction.Output> outputs;

            neoAPI.GenerateInputsOutputs(fromKey, symbol, targets, out inputs, out outputs);

            Transaction tx = new Transaction()
            {
                type    = TransactionType.ContractTransaction,
                version = 0,
                script  = null,
                gas     = -1,
                inputs  = inputs.ToArray(),
                outputs = outputs.ToArray()
            };

            tx.Sign(fromKey);

            return(tx);
        }