Anyone here that knows how to use the transfer function of a contract to transfer those tokens from alice to bob after having loaded the ABI etc.

Mar 23, 2022, 10:31 PM
contract.functions.transfer(receiver, amount).transact({"from": sender}) I am trying this but won't work
Mar 23, 2022, 10:31 PM
Did you add some logic to the contract so that it can transfer Ether?
Mar 23, 2022, 10:46 PM
It is a fork from a long time ago
On testnet basically
Does this work for you then?
Mar 23, 2022, 10:46 PM
What testnet?
Mar 23, 2022, 10:47 PM
bsc
Mar 23, 2022, 10:47 PM
Address?
Mar 23, 2022, 10:47 PM
https://testnet.bscscan.com/address/0xda7ab1a59f98c66215a3f57f70b0a2c65e55df9a
Mar 23, 2022, 10:47 PM
What are you trying to transfer? Ether or token?
Mar 23, 2022, 10:53 PM
The token itself
The only function my program is lacking, pulling tx data related to this token was fine with call()
but transact() idk
Mar 23, 2022, 10:54 PM
Yes I was going to advice you to use call()
Mar 23, 2022, 10:55 PM
Call only works when you want to read data
Not when you want to do an actual transfer
Kinda crazy I cant find anything about this on Google too
Mar 23, 2022, 10:55 PM
Are you using ethers.js right?
Mar 23, 2022, 10:56 PM
web3.py
Mar 23, 2022, 10:56 PM
Oh
Mar 23, 2022, 10:57 PM
But it is the same functionilty
Mar 23, 2022, 10:57 PM
On Ethers you pass a “data” key in the options param of call()
Mar 23, 2022, 10:58 PM
Have you used call to transfer non-native tokens?
I can transfer BNB on BSC, FTM on Fantom etc just fine
Mar 23, 2022, 10:58 PM
https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.send_transaction take a look at this
Mar 23, 2022, 11:00 PM
Yeah that is what this part does basically
That doesn't work for "tokens", only for the main token
For external contract you have to import the ABI then do something
Mar 23, 2022, 11:01 PM
I meant send_transaction
Mar 23, 2022, 11:03 PM
I found out how it works
amount = web3.toWei(amount, 'ether')
# Get the nonce. Prevents one from sending the transaction twice
nonce = web3.eth.getTransactionCount(sender)

token_transfer = contract.functions.transfer(web3.toChecksumAddress(receiver),

web3.toWei(amount, 'wei')).buildTransaction({
'chainId': chain,
'from': sender,
'value': web3.toWei(amount, 'ether'),
'gas': 210000,
'gasPrice': web3.toWei('50', 'gwei'),
'nonce': nonce

})


signed_tx = web3.eth.account.signTransaction(token_transfer, private_key=private_key_1)
print(signed_tx)
tx_hash = web3.eth.sendRawTransaction(web3.toHex(signed_tx.rawTransaction))
Mar 23, 2022, 11:17 PM
how?
Mar 23, 2022, 11:17 PM
They should put something like this in the docs ffs lol
Mar 23, 2022, 11:17 PM
oh okay
Mar 23, 2022, 11:17 PM

© 2024 Draquery.com All rights reserved.