Skip to content

Wrong weiValue calculation in DropERC20_Claim method - multiplies by wei amount instead of token amount #235

@DebabratDas1

Description

@DebabratDas1

In the method DropERC20_Claim, the weiValue is incorrectly calculated when the claim currency is native (e.g., ETH).
Currently, it multiplies the amount in wei by pricePerToken, instead of multiplying the amount of tokens (as a count) by the pricePerToken.

Thus, the gas transaction sends an extremely large amount of native currency, much higher than intended.

📋 Current Behavior (Bug)
Inside DropERC20_Claim:

BigInteger bigInteger = BigInteger.Parse(amount.ToWei()).AdjustDecimals(18, toDecimals);
BigInteger weiValue = ((activeClaimCondition.Currency == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ? (bigInteger * activeClaimCondition.PricePerToken) : BigInteger.Zero);

The bigInteger represents amount in wei, not token count.
Multiplying bigInteger (already in wei) by pricePerToken causes wei overflows.

Example:

Price per token: 1 ETH (1e18 wei)
User claims 2 tokens
amount = "2"
amount.ToWei() = 2 × 10¹⁸ wei
Calculation done: 2 × 10¹⁸ × 1 × 10¹⁸ = 2 × 10³⁶ wei (Wrong!)
Instead, should send 2 × 1 ETH = 2 ETH (2 × 10¹⁸ wei).

✅ Expected Behavior

Multiply the token amount (count), not the wei value, by the pricePerToken.
The calculation should be:

BigInteger tokenAmount = BigInteger.Parse(amount);BigInteger weiValue = (activeClaimCondition.Currency == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ? (tokenAmount * activeClaimCondition.PricePerToken) : BigInteger.Zero;

🧪 Steps to Reproduce

Set up a DropERC20 contract with a claim price of 1 ETH per token.
Call DropERC20_Claim requesting 2 tokens.
Observe that the transaction tries to send 2e36 wei instead of 2e18 wei.

💻 Environment
Thirdweb SDK Version: [v5.19.2]
Platform: [Unity / WebGL / Android / iOS]
Blockchain: [Ethereum / Polygon / Soneium / etc.]

Metadata

Metadata

Assignees

Labels

.NET SDKbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions