OneKeyHQ / OneKeyHQ/hardware-js-sdk

我调用了硬件的签名成功签名,但是无法将交易广播出去

Open
#474 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
35
Forks
39
Avg merge
21h 27m
Merged PRs (30d)
43

Description

const guiji = (): void => {
// let str=getFirstTwoChars('0xd11A69E04F8904c5966650746Ef4513B8C531a1c')

// let dt=usdtToWei(2,str);
// console.log(dt)

// ERC-20 ABI
const erc20Abi = [
"function transfer(address to, uint256 value) public returns (bool)"
];

//ERC-20 合约地址
const erc20ContractAddress = "0x55d398326f99059ff775485246999027b3197955";
const mainnetProvider = ethers.getDefaultProvider('https://bsc-dataseed.binance.org');

// const noc=mainnetProvider.getTransactionCount("0xd11A69E04F8904c5966650746Ef4513B8C531a1c")
// 创建 ERC-20 合约实例
const erc20Contract = new ethers.Contract(erc20ContractAddress, erc20Abi, mainnetProvider);

// 接收地址
const toAddress = "0xd11A69E04F8904c5966650746Ef4513B8C531a1c";

// 转账金额:1000 USDT,假设 USDT 有 18 位小数
const amount = ethers.parseUnits("1", 18);

// 编码交易数据
const encodedData = erc20Contract.interface.encodeFunctionData("transfer", [toAddress, amount]);

console.log(encodedData);
// 1. Create transaction parameters
const txParams = {
to: '0x55d398326f99059fF775485246999027B3197955',
value: '0x0',
data: encodedData,
chainId: 56,
nonce: '0xca3e',
// maxFeePerGas: '0x14',
// maxPriorityFeePerGas: '0x0',
gasLimit: '0xca3e',
gasPrice: "0xb2d05e00"
};
HardwareSDK.evmSignTransaction(data.value.payload[0].connectId, data.value.payload[0].deviceId, {
path: "m/44'/60'/0'/0/10",
transaction: txParams,
chainId: 56
}).then((result11: any) => {
// 在这里获取成功的结果
console.log('成功:', result11.success);

if (result11.success) {
  // 3. Build signed transaction
  const sig = splitSignature(result11.payload);
  // 序列化交易

  const rawTx = serialize({
to: '0x55d398326f99059fF775485246999027B3197955',
value: '0x0',
data: encodedData,
chainId: 56,
nonce: 0,
// maxFeePerGas: '0x14',
// maxPriorityFeePerGas: '0x0',
gasLimit: '0xca3e',
gasPrice: "0xb2d05e00"

}, sig);

  /// 使用 ethers.js 广播交易
  const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
  const wallet = new ethers.Wallet('', provider);
  wallet.sendTransaction({ data: rawTx })

.then((tx) => {
console.log('交易已广播,交易哈希:', tx.hash);
})
.catch((error) => {
console.error('广播失败:', error);
});

} else {
  ElMessage({
    message: h('p', { style: 'line-height: 1; font-size: 14px' }, [
      h('span', { style: 'color: red' }, '地址归集失败,请重新连接设备!')
    ]),
  })
}

})
.catch((error11: any) => {
// 在这里处理错误
console.error('失败:', error11);
ElMessage({
message: h('p', { style: 'line-height: 1; font-size: 14px' }, [
h('span', { style: 'color: red' }, '地址归集失败,请重新连接设备!')
]),
})
});;

}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue body's HardwareSDK.evmSignTransaction call, serialize step, and wallet.sendTransaction broadcast path. Reproduce the failure and inspect the returned error and signed payload, then verify that the provider, transaction fields, and broadcast method are compatible. Done means a successfully signed transaction is accepted by the configured network and its hash is returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
blockchain, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.