Ethereum: Web3 Contract (React) – SafeERC20 Low Level Call failed with ERC20 Token (USDT)

Ethereum: Web3 Contract (React) – Safeerc20 Low level called ERC20 Token (USDT)

As a development of the concept with the concept of interactive blockchain networks. .

The problem

The specifically, when a contract built in Ethereum (such as Esterscan) is used, attempts to call a function with an ERC20 token (such as USDT) triggers a failure.

The symptoms

The symptoms are as follows:

1.

2.

3.

The solution

To solve this problem, you have some options:

1.

  • Implement a backup mechanism

    Ethereum: Web3 Contract (React) - SafeERC20 Low Level Call failed with ERC20 Token (USDT)

    :

Example of code

Here is a fragment of example code in solidity (the programming language used for Ethereum’s intelligent contracts) that demonstrates how it could implement a response mechanism:

`Solidity

Pragma solidity ^0.8.0;

Safeerc20Fallback Contract {

CALLFUNCTION FUNCTION () Public {

// First, try to call the function with Eth

if (msg.gender.balance> 1010 * 18) {

// If you succeed, return the value of the variable

uint256 result = msg.value / 10 ** 18;

Return result;

}

// If you are not successful, try to call the function with a token erc20

address [] memory tokens = [address (0x89f8c7ce9e77fbc2a3bc6bb5da1bf6cc4bfc94ce);

for (uint256 i = 0; i

// Obtain the Token contract

Token contract = token (address (tokens [i]));

// Try to call the function with the token

uint256 results = contract.callfunction ();

// If you succeed, return the value of the variable

If (result> 0) {

Return result;

}

}

// If it is not successful for both methods, reverse the transaction

Revert ();

}

}

Token structure {

Address the public token;

}

`

Conclusion

Safeerc20 low level calls with tokens ERC20 when Ethereum are used. Demonstrating how to implement an response mechanism for such cases.

The cause of the cause and development of its intelligent contract or web application.

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片