Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86duaznam - BSEthereum - Error when making a transaction with NeoX… #85

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Fix error when making a transaction with NeoX on TestNet",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
20 changes: 12 additions & 8 deletions packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,26 @@ export class BSEthereum<BSCustomName extends string = string>
const decimals = param.intent.tokenDecimals ?? 18
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals)

let transactionParams: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
const gasPrice = await provider.getGasPrice()

let transactionParams: ethers.utils.Deferrable<ethers.providers.TransactionRequest> = {
gasPrice,
}

const isNative =
BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper.normalizeHash(param.intent.tokenHash)
if (isNative) {
const gasPrice = await provider.getGasPrice()
transactionParams = {
to: param.intent.receiverAddress,
value: amount,
gasPrice,
}
transactionParams.to = param.intent.receiverAddress
transactionParams.value = amount
} else {
const contract = new ethers.Contract(param.intent.tokenHash, [
'function transfer(address to, uint amount) returns (bool)',
])
transactionParams = await contract.populateTransaction.transfer(param.intent.receiverAddress, amount)
const populatedTransaction = await contract.populateTransaction.transfer(param.intent.receiverAddress, amount)
transactionParams = {
...populatedTransaction,
...transactionParams,
}
}

const transaction = await signer.sendTransaction(transactionParams)
Expand Down
Loading