hi can you help me I want to get tether balance of an account and send tether to my contract using web3 and send the tether in the contract to another address. and I have no idea how to do it. I didn't find any tutorial
-
Does this https://ethereum.stackexchange.com/questions/17322/using-solidity-how-can-i-transfer-erc20-tokens-from-the-current-address-to-anot work for you? – Ismael Jun 30 '21 at 01:26
3 Answers
I think this is the way to transfer USDT or any ERc20 token on any EVM chain with web3JS:-
Step 1: see the code. e.g. this is USDT (Polygon Matic) solidity code https://polygonscan.com/address/0x2791bca1f2de4661ed88a30c99a7a9449aa84174#code#L121
step 2: find the function which transfer tokens.

step 3: get ABI code most of the trusted NFT-721 give their solidity source code, from there you can get ABI codes.
finally: use web3js .send() methond to interact with that function.
let contract = new web3.eth.Contract(ABI, contractadddress)
contract.methods.transferProxyOwnership("0x23498...").send({<gas fee settings>})
.then(receipt =>console.log(receipt))
.catch(err=>console.log(err))
learn proper web3js from youtube & official docs https://web3js.readthedocs.io/en/v1.2.11/index.html
- 691
- 3
- 11
here is a solution for you.
Use Zapper.fi API to get the USDT balance of an address (Store this).
Then use either their API features or plain Web3.js to interact with the USDT smart contract and execute the transferFrom function with this as the "_value".
That's it! I hope this gives you some guidance :)
- 995
- 5
- 14
-
hi thanks for your quick answer but i want to know how to interact with USDT contract in solidity. how to use its functions and methods in my solidity contract and get USDT balance of an input address – Meysam Jun 29 '21 at 13:19
-
Check this: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html – AvocadoChocolate Jun 29 '21 at 13:37
I think you must put a deposit function on your contract. You cannot transfer randomly to a contract tokens, it will be reverted, only to address.
- 11
- 1
-
1Important correction: it would not revert in most cases. Meaning the USDT would be stuck where you sent them, assuming you didn't plan a way to get them out – natewelch_ Apr 27 '22 at 18:13