/// <summary> /// Deposit ERC20 Tokens /// </summary> /// <param name="tokenAddress">The Token Address</param> /// <param name="userAddress">The Address of the User</param> /// <param name="amount">Amount to Deposit</param> /// <param name="options">Matic Transaction Options</param> /// <returns></returns> public async Task <string> DepositErc20Tokens(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))) { 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>'"); } //Deposit ERC20 Tokens DepositModel depositModel = new DepositModel() { TokenAddress = tokenAddress, UserAddress = userAddress, Amount = amount }; string response = await maticRootChainContract.Deposit(depositModel, options); return(response); }
/// <summary> /// Deposits given amount of ether (wei) to the child chain /// </summary> /// <param name="profileFrom">profile of the sender</param> /// <param name="amount">amount of ether (wei) to send</param> /// <returns>transaction object</returns> public async Task <BCTransaction> Deposit(Profile profileFrom, BigInteger amount) { if (rootChainContract != null) { var depositPlasmaTx = new PlasmaCore.Transactions.Transaction(); depositPlasmaTx.AddOutput(profileFrom.ID, ZERO_ADDRESS, amount); RawTransactionEncoder txEncoder = new RawTransactionEncoder(); byte[] encodedDepositTx = txEncoder.EncodeRaw(depositPlasmaTx); var depositTx = await rootChainContract.Deposit(web3, profileFrom.ID, encodedDepositTx, amount); string signedDepositTx = await SignTransaction(profileFrom, depositTx); return(await SubmitTransactionOnRootChain(web3, signedDepositTx)); } return(null); }