コード例 #1
0
        public string SignTransaction(EthereumKey keys, int nonce, string receiveAddress, BigInteger amount, BigInteger gasPrice, BigInteger gasLimit, string data = null)
        {
            var realAmount = System.Numerics.BigInteger.Parse(amount.ToString());

            //Create a transaction from scratch
            var tx = new Phantasma.Ethereum.Signer.Transaction(receiveAddress, realAmount, nonce,
                                                               System.Numerics.BigInteger.Parse(gasPrice.ToString()),
                                                               System.Numerics.BigInteger.Parse(gasLimit.ToString()),
                                                               data);

            tx.Sign(new EthECKey(keys.PrivateKey, true));

            var encoded = tx.GetRLPEncoded();

            return("0x" + Base16.Encode(encoded));
        }
コード例 #2
0
        public string SignTokenTransaction(EthereumKey keys, int nonce, string tokenContract, string receiveAddress, BigInteger amount, BigInteger gasPrice, BigInteger gasLimit)
        {
            var transferMethodHash = "a9059cbb";
            var to        = receiveAddress.Substring(2).PadLeft(64, '0');
            var amountHex = amount.ToHex().PadLeft(64, '0');

            //Create a transaction from scratch
            var tx = new Phantasma.Ethereum.Signer.Transaction(tokenContract,
                                                               0, // Ammount of ETH to be transfered (0)
                                                               nonce,
                                                               System.Numerics.BigInteger.Parse(gasPrice.ToString()),
                                                               System.Numerics.BigInteger.Parse(gasLimit.ToString()),
                                                               transferMethodHash + to + amountHex);

            tx.Sign(new EthECKey(keys.PrivateKey, true));

            var encoded = tx.GetRLPEncoded();

            return("0x" + Base16.Encode(encoded));
        }