harmony-one / sdk

Javascript SDK of Harmony protocol.
MIT License
91 stars 44 forks source link

invalid chain id for signer for #112

Open yurenji opened 2 years ago

yurenji commented 2 years ago

I tried to create a transaction following the sdk example:

  const hmy = new Harmony(
    'https://api.fuzz.fi/',
    {
        chainType: ChainType.Harmony,
        chainId: ChainID.Harmony,
    },
  );
  hmy.wallet.addByPrivateKey('');
  const txn = hmy.transactions.newTx({
    to: receiver_address,
    value: new Unit(1).asOne().toWei(),
    gasLimit: '21000',
    shardID: 0,
    toShardID: 0,
    gasPrice: new hmy.utils.Unit('31').asGwei().toWei(),
  });
  const signedTxn = await hmy.wallet.signTransaction(txn);
  const txnHash = await hmy.blockchain.sendTransaction(signedTxn);

but got the following error msg:

{
  jsonrpc: '2.0',
  id: 3,
  error: {
    code: -32000,
    message: 'blockchain chain id:1, given 2: invalid chain id for signer'
  },
  req: {
    payload: {
      jsonrpc: '2.0',
      id: 3,
      method: 'hmy_sendRawTransaction',
      params: [Array]
    },
    url: 'https://api.fuzz.fi/',
    options: {
      method: 'POST',
      timeout: 120000,
      headers: [Object],
      user: null,
      password: null
    }
  },
  responseType: 'raw'
}

Not sure why since only one chainId is provided.