示例#1
0
        /// <summary>
        /// Start withdraw process with given amount for token.
        /// </summary>
        /// <param name="tokenAddress">Must be a valid ERC20 Token Address</param>
        /// <param name="amount">must be token amount in wei</param>
        /// <param name="options">Matic Transaction Options</param>
        /// <returns></returns>
        public async Task <string> StartWithdraw(string tokenAddress, BigInteger amount, MaticTransactionOptions options)
        {
            //check if the options are correctly set
            if ((options != null) && (String.IsNullOrEmpty(options.From) || String.IsNullOrEmpty(options.SenderPrivateKey) || String.IsNullOrEmpty(tokenAddress) || amount == null))
            {
                throw new Exception("Parameters required for the transaction on Matic Network are missing");
            }

            //If the Private Key was not sent in the options assign the one set in the wallet. If both are null, throw an exception
            if (string.IsNullOrEmpty(options.SenderPrivateKey))
            {
                options.SenderPrivateKey = Wallet;
            }
            if (String.IsNullOrEmpty(options.SenderPrivateKey))
            {
                throw new Exception("Please provide the private Key first, using 'Matic.Wallet = <PrivateKey>'");
            }


            //Get the Contract Using the token Address
            ERC20TokenContract erc20Contract = new ERC20TokenContract(MaticProvider, tokenAddress);
            ERC20WithdrawModel withdrawModel = new ERC20WithdrawModel()
            {
                Amount = amount
            };
            string response = await erc20Contract.Withdraw(withdrawModel, options);

            return(response);
        }
示例#2
0
        /// <summary>
        /// The transfer function is used to Perform Transfers from one Address to another
        /// </summary>
        /// <param name="tokenAddress">Source Address and Signer</param>
        /// <param name="userAddress">Address of the reciepient</param>
        /// <param name="amount">The Amount (In wei) of tokens to be transfered to the reciepient</param>
        /// <param name="options">Matic Transaction Options</param>
        /// <returns></returns>
        public async Task <string> TransferTokens(string tokenAddress, string userAddress, BigInteger amount, MaticTransactionOptions options)
        {
            //check if the options are correctly set
            if ((options != null) && (String.IsNullOrEmpty(options.From) || String.IsNullOrEmpty(tokenAddress) || amount == null))
            {
                throw new Exception("Parameters required for the transaction on Matic Network are missing");
            }

            //If the Private Key was not sent in the options assign the one set in the wallet. If both are null, throw an exception
            if (string.IsNullOrEmpty(options.SenderPrivateKey))
            {
                options.SenderPrivateKey = Wallet;
            }
            if (String.IsNullOrEmpty(options.SenderPrivateKey))
            {
                throw new Exception("Please provide the private Key first, using 'Matic.Wallet = <PrivateKey>'");
            }


            string web3Provider = MaticProvider;

            //Set The web3 Object to the Parent Web3 Object if UseParent is set to true
            if (options.UseParent)
            {
                web3Provider = ParentProvider;
            }

            //Get the contract using the token Address
            ERC20TokenContract erc20TokenContract = new ERC20TokenContract(web3Provider, tokenAddress);

            //Make the Transfer
            ERC20TransferModel transferModel = new ERC20TransferModel()
            {
                To    = userAddress,
                Value = new HexBigInteger(amount)
            };
            string response = await erc20TokenContract.Transfer(transferModel, options);

            return(response);
        }