我正在使用 0x 将我的 Binance 代币换成其他受人尊敬的代币。我从 0X API 获得了所需的数据,但每次它都显示 EVM 无故错误地恢复了事务。
这些是交易时的日志 -
signed { messageHash: '0x6fd9e426b7c085a740b261c4fc606e88767c4819150a169a028079024923afaa', v: '0x94', r: '0xdbdb5aab20584e6a4e65ec3153894222a44df0f7b661dab19c6b6b1cb3c2519a', s: '0x3210e091a62ec3f92d22bda0cbd995b193eab36a97e95b157e76f6808257739f', rawTransaction: '',事务哈希:'0x76be9ab418105941a6cc1dd41829c4658278a469edd1c0dd84349fb574e92ec8' } sendSignedTransaction data 0x76be9ab418105941a6cc1dd41829c4658278a469edd1c0dd84349fb574e92ec8 swap error because of : Error: Transaction has been reverted by the EVM: { "blockHash": "0x6475ed2252aab3ed3aa2f91aa81ea9f2833c68fa1182beee3b4c76fb83a0fcfa", "blockNumber": 12297880, "contractAddress": null, "cumulativeGasUsed": 54244448, "from “:“0xa859d1f24f27b550bf4ba3b54d15d88d51df5018”,“gasUsed”:32362,“日志”:[],“logsBloom”:“0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": false, "to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff", "transactionHash": "0x76be9ab418105941a6cc1dd41829c4658278a469edd1c0dd84349fb574e92ec8", "transactionIndex": 298, "type": "0x0" } at Object.TransactionError (/node_modules/web3-core-helpers/lib/errors.js:87:21) 在 Object.TransactionRevertedWithoutReasonError (/node_modules/web3-core-helpers/lib/errors.js:98:21) 在 /node_modules/web3 -core-method/lib/index.js:393:57 at processTicksAndRejections (internal/process/task_queues.js:93:5) { 收据: { blockHash: '0x6475ed2252aab3ed3aa2f91aa81ea9f2833c68fa1182beee3b4c76fb83a0fcfa', blockNumber: 122978Used: 5444, null ,来自:'0xa859d1f24f27b550bf4ba3b54d15d88d51df5018',gasUsed:32362,日志:[],logsBloom:'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', status: false, to: '0xdef1c0ded9bec7f1a1670819833240f027b25eff', transactionHash: '0x76be9ab418105941a6cc1dd41829c4658278a469edd1c0dd84349fb574e92ec8', transactionIndex: 298, type: '0x0' } }} }} }
这是我们的代币——
https://bscscan.com/address/0x67b198a69f8cdab39524a00554c3dd50b6ba7fec
JS-
常量响应=等待获取(https://bsc.api.0x.org/swap/v1/quote?buyToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&sellToken=0x67B198A69F8cdAb39524a00554c3DD50B6bA7feC&sellAmount=1000000000000000000000000000000 常量 jsn = 等待 response.json();
const account = web3.eth.accounts.privateKeyToAccount(
'privatekey'
);
const signed = await account.signTransaction(jsn);
console.log('signed', signed);
const swap = await web3.eth.sendSignedTransaction(
signed.rawTransaction,
async (err, data) => {
if (err) {
console.error('sendSignedTransaction error', err);
} else {
console.error('sendSignedTransaction data', data);
}
}
);