@@ -265,17 +265,25 @@ public static async Task<BigInteger> GetTransactionCount(this IThirdwebWallet wa
265265 }
266266
267267 /// <summary>
268- /// Transfers the specified amount of Wei to the specified address.
268+ /// Transfers the specified amount of Wei to the specified address. Passing tokenAddress will override this function to transfer ERC20 tokens.
269269 /// </summary>
270270 /// <param name="wallet">The wallet to transfer from.</param>
271271 /// <param name="chainId">The chain ID to transfer on.</param>
272272 /// <param name="toAddress">The address to transfer to.</param>
273273 /// <param name="weiAmount">The amount of Wei to transfer.</param>
274+ /// <param name="tokenAddress">The optional token address to transfer from. Defaults to the native token address (ETH or equivalent).</param>
275+ /// <returns>A task that represents the asynchronous operation. The task result contains the transaction receipt.</returns>
274276 /// <returns>A task that represents the asynchronous operation. The task result contains the transaction receipt.</returns>
275277 /// <exception cref="ArgumentNullException">Thrown when the wallet is null.</exception>
276278 /// <exception cref="ArgumentOutOfRangeException">Thrown when the chain ID is less than or equal to 0.</exception>
277279 /// <exception cref="ArgumentException">Thrown when the recipient address is null or empty.</exception>
278- public static async Task < ThirdwebTransactionReceipt > Transfer ( this IThirdwebWallet wallet , BigInteger chainId , string toAddress , BigInteger weiAmount )
280+ public static async Task < ThirdwebTransactionReceipt > Transfer (
281+ this IThirdwebWallet wallet ,
282+ BigInteger chainId ,
283+ string toAddress ,
284+ BigInteger weiAmount ,
285+ string tokenAddress = Constants . NATIVE_TOKEN_ADDRESS
286+ )
279287 {
280288 if ( wallet == null )
281289 {
@@ -297,9 +305,17 @@ public static async Task<ThirdwebTransactionReceipt> Transfer(this IThirdwebWall
297305 throw new ArgumentOutOfRangeException ( nameof ( weiAmount ) , "Amount must be 0 or greater." ) ;
298306 }
299307
300- var txInput = new ThirdwebTransactionInput ( chainId ) { To = toAddress , Value = new HexBigInteger ( weiAmount ) } ;
301- var tx = await ThirdwebTransaction . Create ( wallet , txInput ) . ConfigureAwait ( false ) ;
302- return await ThirdwebTransaction . SendAndWaitForTransactionReceipt ( tx ) . ConfigureAwait ( false ) ;
308+ if ( tokenAddress != Constants . NATIVE_TOKEN_ADDRESS )
309+ {
310+ var erc20Contract = await ThirdwebContract . Create ( wallet . Client , tokenAddress , chainId ) . ConfigureAwait ( false ) ;
311+ return await erc20Contract . ERC20_Transfer ( wallet , toAddress , weiAmount ) . ConfigureAwait ( false ) ;
312+ }
313+ else
314+ {
315+ var txInput = new ThirdwebTransactionInput ( chainId ) { To = toAddress , Value = new HexBigInteger ( weiAmount ) } ;
316+ var tx = await ThirdwebTransaction . Create ( wallet , txInput ) . ConfigureAwait ( false ) ;
317+ return await ThirdwebTransaction . SendAndWaitForTransactionReceipt ( tx ) . ConfigureAwait ( false ) ;
318+ }
303319 }
304320
305321 /// <summary>
0 commit comments