@@ -265,17 +265,25 @@ public static async Task<BigInteger> GetTransactionCount(this IThirdwebWallet wa
265
265
}
266
266
267
267
/// <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.
269
269
/// </summary>
270
270
/// <param name="wallet">The wallet to transfer from.</param>
271
271
/// <param name="chainId">The chain ID to transfer on.</param>
272
272
/// <param name="toAddress">The address to transfer to.</param>
273
273
/// <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>
274
276
/// <returns>A task that represents the asynchronous operation. The task result contains the transaction receipt.</returns>
275
277
/// <exception cref="ArgumentNullException">Thrown when the wallet is null.</exception>
276
278
/// <exception cref="ArgumentOutOfRangeException">Thrown when the chain ID is less than or equal to 0.</exception>
277
279
/// <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
+ )
279
287
{
280
288
if ( wallet == null )
281
289
{
@@ -297,9 +305,17 @@ public static async Task<ThirdwebTransactionReceipt> Transfer(this IThirdwebWall
297
305
throw new ArgumentOutOfRangeException ( nameof ( weiAmount ) , "Amount must be 0 or greater." ) ;
298
306
}
299
307
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
+ }
303
319
}
304
320
305
321
/// <summary>
0 commit comments