public static async Task <MaticTransactionOptions> GetTransactionEstimate(DepositERC721Model depositModel, MaticTransactionOptions options, Function function)
        {
            try
            {
                //Get the Account of the Sender
                Account account = GetAccount(options.SenderPrivateKey, options.ChainId);

                //Get the Gas Limit
                HexBigInteger gasLimit = await function.EstimateGasAsync(account.Address, null, null, depositModel.TokenAddress, depositModel.UserAddress, (BigInteger)depositModel.TokenId);

                //Get the Gas Price Estimate
                GasPriceEstimator gasPriceEstimator = new GasPriceEstimator();
                GasPriceEstimate  gasPriceEstimate  = await gasPriceEstimator.GetRecommendedGasPriceFromNetwork();

                //Fill the options
                options.GasPrice = (decimal)gasPriceEstimate.AverageGwei;
                options.GasLimit = gasLimit;
                options.From     = account.Address;
                return(options);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to Fill options because " + ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Deposit ERC721 Tokens
        /// </summary>
        /// <param name="tokenAddress">The Address of the Contract</param>
        /// <param name="userAddress">The Address of the User</param>
        /// <param name="tokenId">The Token Id</param>
        /// <param name="options">The Matic Transaction Options</param>
        /// <returns></returns>
        public async Task <string> DepositERC721Tokens(string tokenAddress, string userAddress, int?tokenId, MaticTransactionOptions options = null)
        {
            //check if the options are correctly set
            if ((options != null) && (String.IsNullOrEmpty(options.From) || String.IsNullOrEmpty(tokenAddress) || tokenId == 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>'");
            }


            DepositERC721Model depositModel = new DepositERC721Model()
            {
                TokenAddress = tokenAddress,
                UserAddress  = userAddress,
                TokenId      = tokenId.Value
            };

            //Make the deposit
            string response = await maticRootChainContract.DepositERC721(depositModel, options);

            return(response);
        }
예제 #3
0
        /// <summary>
        /// Deposit ERC 721
        /// </summary>
        /// <param name="tokenAddress">Must be a valic ERC721 Token</param>
        /// <param name="userAddress">User Address</param>
        /// <param name="tokenId">Mapped Token Index</param>
        /// <param name="options">Matic Trnsaction Options</param>
        /// <returns></returns>
        public async Task <string> DepositERC721(DepositERC721Model depositModel, MaticTransactionOptions options)
        {
            //Get the Contract instance by Creating a Web3 client from the Sender's Private Key
            Web3     web3Client       = Web3ClientHelper.GetWeb3Client(ProviderUrl, options.SenderPrivateKey);
            Contract contractInstance = web3Client.Eth.GetContract(ABI, ContractAddress);
            Function function         = contractInstance.GetFunction("depositERC721");

            //Fill the options
            options = await TransactionEstimateHelper.GetTransactionEstimate(depositModel, options, function);

            string response = await function.SendTransactionAsync(options.From, new HexBigInteger(options.GasLimit), new HexBigInteger(options.GasPrice.ToString()), null, depositModel.TokenAddress, depositModel.UserAddress, depositModel.TokenId);

            return(response);
        }