question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sendTransaction based on sendToken

See original GitHub issue

There could be a more generalized version of sendToken that sends a custom transaction. So, it would get account number, sequence and chain id, use an existing client, post request (base_req and body) to an API to get a formed tx, sign it locally and broadcast it to the chain.

Something like this:

async sendTransaction({ state }, { type, body }) { // don't mind the state, it's a Vuex thing
  const { accountNumber, sequence } = await state.client.getNonce();
  const address = state.client.senderAddress;
  const chain_id = await state.client.getChainId();
  const req = {
    base_req: { chain_id, from: address },
    creator: address,
    ...body,
  };
  const { data } = await axios.post(`${API}/${chain_id}/${type}`, req);
  const { msg, fee, memo } = data.value;
  const signBytes = makeSignBytes(
    msg,
    fee,
    chain_id,
    memo,
    accountNumber,
    sequence
  );
  const signatures = [await state.wallet.sign(signBytes)];
  const signedTx = { msg: msg, fee, memo, signatures };
  return await state.client.postTx(signedTx);
}

Pretty useful method to have.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
webmaster128commented, Jul 17, 2020

Very good idea.

Looking at packages/cosmwasm/src/signingcosmwasmclient.ts you also see a lot of repetition of this code:

    const fee = this.fees.exec;
    const { accountNumber, sequence } = await this.getNonce();
    const chainId = await this.getChainId();
    const signBytes = makeSignBytes([executeMsg], fee, chainId, memo, accountNumber, sequence);
    const signature = await this.signer.sign(this.senderAddress, signBytes);
    const signedTx: StdTx = {
      msg: [executeMsg],
      fee: fee,
      memo: memo,
      signatures: [signature],
    };

    const result = await this.postTx(signedTx);
    if (isPostTxFailure(result)) {
      throw new Error(createPostTxErrorMessage(result));
    }

So the same sendTransaction should be created in SigningCosmWasmClient and SigningCosmosClient

0reactions
webmaster128commented, Jul 27, 2020

Thank you Ethan! I agree this is a more general solution to the problem. However, I don’t think we will get it sufficiently refned and implemented this week and in 0.22.0. I created a new ticket here: https://github.com/CosmWasm/cosmjs/issues/316. I’ll close this ticket with a smaller change of the current code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

web3 sendTransaction select and send token different than ...
I simply want to send ETH, but on the Polygon Network. Can someone guide me? I am using web3.min.js and spent hours on...
Read more >
How to call my contract's function using sendTransaction
Posting solution to my own question for anyone who needs it. To call a contract function from geth :
Read more >
Send Transactions | Flow Blockchain
sendTransaction (props). Send transaction to network. Provides explicit control over how you pass values.
Read more >
Sending Tokens Using ethers.js - Ethereum.org
Send Token Using ethers.js(5.0). In This Tutorial You'll Learn How To. Import ethers.js; Transfer token; Set gas price according to the ...
Read more >
How to send ERC20 token with Web3.js | by Hideyoshi Moriya
ABI is an interface which represents what functions/state variables a smart contract has. To interact with smart contracts with Web3.js, ABI is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found