Skip to content

Commit 92ab74e

Browse files
committed
Expose ERC20.TransferFrom
1 parent 243bc5f commit 92ab74e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Assets/Thirdweb/Core/Scripts/ERC20.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ public async Task<TransactionResult> Transfer(string to, string amount)
204204
}
205205
}
206206

207+
/// <summary>
208+
/// Transfer a given amount of currency from the given wallet (if permission is granted) to another wallet
209+
/// </summary>
210+
public async Task<TransactionResult> TransferFrom(string from, string to, string amount)
211+
{
212+
if (Utils.IsWebGLBuild())
213+
{
214+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("transferFrom"), Utils.ToJsonStringArray(from, to, amount));
215+
}
216+
else
217+
{
218+
var currency = await Get();
219+
var rawAmountToTransfer = BigInteger.Parse(amount.ToWei()).AdjustDecimals(18, int.Parse(currency.decimals));
220+
return await TransactionManager.ThirdwebWrite(
221+
contractAddress,
222+
new TokenERC20Contract.TransferFromFunction()
223+
{
224+
From = from,
225+
To = to,
226+
Amount = rawAmountToTransfer
227+
}
228+
);
229+
}
230+
}
231+
207232
/// <summary>
208233
/// Burn a given amount of currency
209234
/// </summary>

0 commit comments

Comments
 (0)