Hey there :)
I am trying to use the generate_unsigned_bridge_txn endpoint in the synapse-api to build a script which will send JEWEL from DFK Chain to Harmony in Python.
I believe this API uses the buildBridgeTokenTransaction function.
I am working in Python 3.9 with web3py
I am doing the following:
1) I send a request to the generate_unsigned_bridge_txn endpoint
'fromChain': 53935,
'toChain': 1666600000,
'fromToken': 'JEWEL',
'toToken': 'JEWEL',
'amountFrom': '1000000000000000000',
'addressTo': '0x919d17174Fb22CC1Cfc8748C208104EC62341791'
In plaintext, the above would translate to:
Send 1 JEWEL from DFK Chain to Harmony for JEWEL on Harmony.
2) This is the response I get back from the API is the following (I have shorted unsigned_data so I dont make a mess ๐):
{
'unsigned_data': '0xa9fd8c57000000000000000000000000919d17174f...',
'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
'chainId': 53935,
'value': '1'
}
3) So then I create a transaction object:
transaction = {
'nonce': w3.eth.getTransactionCount(walletAddress),
"chainId": bridgeTransaction["chainId"],
'to': bridgeTransaction["to"],
'gas': 100206,
'gasPrice': w3.eth.gas_price,
'data': bridgeTransaction["unsigned_data"]
}
which looks like
{'nonce': 6,
'chainId': 53935,
'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
'gas': 100206,
'gasPrice': 40000000,
'data': '0xa9fd8c57000000000000000000000000919d17174f...'}
4) I then sign it using sign_transaction
signedTransaction = w3.eth.account.sign_transaction(transaction, privateKey)
5) and send the raw transaction using https://web3py.readthedocs.io/en/stable/web3.eth.html?highlight=sign_transaction#web3.eth.Eth.send_raw_transaction
sentTransaction = w3.eth.send_raw_transaction(signedTransaction.rawTransaction)
6) The problem is the transaction get sent but it fails
Heres the failing transaction of the above example: 0xa799782030cdf5c1e5e927f5624ae42e0e3e1cc2ff9ac71013168482d018474b
I am just wondering why my transaction is failing.
One thing I did notice is there is a difference in the content of the data sent in my failed bridge transaction versus a successful bridge transaction
As highlighted with the two green rectangles - it looks like there are two missing chunks in the data. Not sure if this is the cause but wanted to offer some help.
Here is the full data sent by the failed transaction:
0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c4000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062974fae
I also noticed that the value of my transaction was 0 JEWEL which is odd as the successful transaction had a value of 108.2 JEWEL
I tried to add this value param to the transaction and it didn't like it ๐ค
{'nonce': 9,
'chainId': 53935,
'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
'gas': 100206,
'value': '1000000000000000000',
'gasPrice': 40000000,
'data': '0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c40....'}
TypeError: Transaction had invalid fields: {'value': '1000000000000000000'}