Exemplo n.º 1
0
        /// <summary>
        /// Start withdraw process with given tokenId for token.
        /// </summary>
        /// <param name="tokenAddress">must be valid ERC721 token address</param>
        /// <param name="tokenId">must be token tokenId in wei </param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <string> StartERC721Withdraw(string tokenAddress, int?tokenId, MaticTransactionOptions options)
        {
            //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>'");
            }


            //Get the Contract using the tokenAddress
            ERC721TokenContract erc721TokenContract = new ERC721TokenContract(MaticProvider, tokenAddress);
            ERC721WithdrawModel withdrawalModel     = new ERC721WithdrawModel()
            {
                To      = tokenAddress,
                TokenId = tokenId.Value
            };

            string response = await erc721TokenContract.Withdraw(withdrawalModel, options);

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the ERC721 Token Of the Owner(address) using the index Id
        /// </summary>
        /// <param name="address">The Address of the owner</param>
        /// <param name="tokenAddress">THe Address of the Contract</param>
        /// <param name="index">The index Id</param>
        /// <param name="options">Options for the transaction</param>
        /// <returns></returns>
        public async Task <int> TokenOfOwnerByIndexERC721(string address, string tokenAddress, int index, MaticTransactionOptions options)
        {
            try
            {
                string web3ProviderUrl = MaticProvider;

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

                //Get the ERC721 Contract using the token address of the contract
                ERC721TokenContract erc721Contract = new ERC721TokenContract(MaticProvider, tokenAddress);

                //Get the TokenId from the Contract
                int TokenId = await erc721Contract.GetTokenOfOwnerByIndex(address, index);

                return(TokenId);
            }
            catch (Exception ex)
            {
                throw new Exception($"Could not fetch token by index because: {ex.Message}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get ERC721 Token Balance
        /// </summary>
        /// <param name="userAddress">userAddress holds the address of the user</param>
        /// <param name="tokenAddress">tokenAddress holds the address of the contract</param>
        /// <param name="options">options holds the options to be passed for the transaction.</param>
        /// <returns>BigInteger</returns>
        public async Task <BigInteger> BalanceOfERC721(string userAddress, string tokenAddress, MaticTransactionOptions options)
        {
            try
            {
                string web3ProviderUrl = MaticProvider;

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

                //Get the ERC721 Contract using the token address of the contract
                ERC721TokenContract erc721Contract = new ERC721TokenContract(web3ProviderUrl, tokenAddress);

                //Get the Balance of the User from the Contract
                BigInteger balance = await erc721Contract.BalanceOf(userAddress);

                return(balance);
            }
            catch (Exception ex)
            {
                throw new Exception($"Could not fetch ERC721 balance for ");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// TransferERC721Tokens
        /// </summary>
        /// <param name="tokenAddress">Address of the Token's Contract</param>
        /// <param name="userAddress">Address of the User</param>
        /// <param name="tokenId">The Index of the Token on Matic</param>
        /// <param name="options">Matic Transaction Options</param>
        /// <returns></returns>
        public async Task <string> TransferERC721Tokens(string tokenAddress, string userAddress, int?tokenId, MaticTransactionOptions options)
        {
            Web3 web3Object = web3;

            //Use the ParentWeb3 if UseParent is set to true
            if (options.UseParent)
            {
                web3Object = ParentWeb3;
            }

            //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 with the token Address
            ERC721TokenContract erc721TokenContract = new ERC721TokenContract(MaticProvider, tokenAddress);

            //Send the Transaction
            ERC721TransferFromModel transferModel = new ERC721TransferFromModel()
            {
                From    = userAddress,
                To      = tokenAddress,
                TokenId = tokenId.Value
            };

            string response = await erc721TokenContract.TransferFrom(transferModel, options);

            return(response);
        }