-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
docs: constructing txs for /cosmos/tx/v1beta1/txs endpoint
#20421
base: main
Are you sure you want to change the base?
Conversation
WalkthroughWalkthroughThe changes in Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant JSON
participant Protobuf
participant txFactory
participant txBuilder
participant authclient
participant Base64
User->>JSON: Provide transaction details
JSON->>Protobuf: Convert JSON to Protobuf
Protobuf->>txFactory: Initialize with chain ID, keybase, sign mode
txFactory->>txBuilder: Create and configure transaction
txBuilder->>authclient: Sign transaction
authclient->>txBuilder: Return signed transaction
txBuilder->>Base64: Encode transaction bytes
Base64->>User: Return base64 encoded transaction
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
/cosmos/tx/v1beta1/txs endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Out of diff range and nitpick comments (7)
docs/learn/advanced/01-transactions.md (7)
206-266
: Clarify the transaction construction process for better understanding.The steps outlined for handling JSON to Protobuf conversion are comprehensive but could benefit from a brief introductory sentence to enhance clarity. Consider adding an introductory line that summarizes what this section aims to achieve before diving into the detailed steps.
Line range hint
91-91
: Improve clarity in the description ofSIGN_MODE_DIRECT_AUX
.Consider rephrasing to include a necessary preposition for better readability:
- no need an additional step to gather other signers' ones + no need for an additional step to gather other signers' information
Line range hint
97-97
: Enhance readability by using a comma in complex sentences.- ...hardware wallets and it is included in the v0.50 release. + ...hardware wallets, and it is included in the v0.50 release.Adding a comma before "and" can help in separating the clauses for better readability, especially in longer sentences.
Line range hint
107-107
: Use more formal language in technical documentation.- While we can not accept the implementation of the sign mode... + While we cannot accept the implementation of the sign mode...Using "cannot" instead of "can not" provides a more formal and compact form, which is generally preferred in written English.
Line range hint
127-127
: Correct grammatical errors to maintain professionalism.- Each `sdk.Msg`s is related to exactly one Protobuf [`Msg` service] + Each `sdk.Msg` is related to exactly one Protobuf [`Msg` service]The verb "is" should agree with the singular noun "sdk.Msg". Additionally, correct the article before "SDK":
- A SDK app router automatically maps every `sdk.Msg` to a corresponding RPC. + An SDK app router automatically maps every `sdk.Msg` to a corresponding RPC.
Line range hint
143-147
: Refine the list format for better presentation.Consider removing the commas after the list item names to enhance the formatting consistency:
- * `GasLimit`, option chosen by the users for how to calculate how much gas they will need to pay. + * `GasLimit` - option chosen by the users for how to calculate how much gas they will need to pay. - * `Memo`, a note or comment to send with the transaction. + * `Memo` - a note or comment to send with the transaction. - * `FeeAmount`, the maximum amount the user is willing to pay in fees. + * `FeeAmount` - the maximum amount the user is willing to pay in fees. - * `TimeoutHeight`, block height until which the transaction is valid. + * `TimeoutHeight` - block height until which the transaction is valid. - * `Signatures`, the array of signatures from all signers of the transaction. + * `Signatures` - the array of signatures from all signers of the transaction.
Line range hint
162-162
: Correct spelling for better accuracy.- Here's a pseudo-code snippet of how to generate and encode a... + Here's a pseudocode snippet of how to generate and encode a..."Pseudocode" is conventionally spelled as one word in technical contexts.
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- docs/learn/advanced/01-transactions.md (1 hunks)
Additional Context Used
LanguageTool (13)
docs/learn/advanced/01-transactions.md (13)
Near line 91: Possible missing preposition found.
Context: ...ody` and their own signer info (no need an additional step to gather other signers...
Near line 97: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...r signing experience on hardware wallets and it is included in the v0.50 release. In...
Near line 107: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... sign mode to the Cosmos-SDK. While we can not accept the implementation of the sign m...
Near line 127: The verb “is” doesn’t seem to fit in this context, “are” is probably more formally correct.
Context: ...espondingMsgServer
. Eachsdk.Msg
s is related to exactly one Protobuf [Msg
...
Near line 127: Use “An” instead of ‘A’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...d inside each module'stx.proto
file. A SDK app router automatically maps every...
Near line 143: Loose punctuation mark.
Context: ...ncluded in the transaction. *GasLimit
, option chosen by the users for how to c...
Near line 144: Loose punctuation mark.
Context: ...much gas they will need to pay. *Memo
, a note or comment to send with the tran...
Near line 145: Loose punctuation mark.
Context: ...send with the transaction. *FeeAmount
, the maximum amount the user is willing ...
Near line 146: Loose punctuation mark.
Context: ...illing to pay in fees. *TimeoutHeight
, block height until which the transactio...
Near line 147: Loose punctuation mark.
Context: ...the transaction is valid. *Signatures
, the array of signatures from all signer...
Near line 162: This word is normally spelled as one.
Context: ...SIGN_MODE_LEGACY_AMINO_JSON`). Here's a pseudo-code snippet of how to generate and encode a...
Near line 228: Do not mix variants of the same word (‘serialise’ and ‘serialize’) within a single text.
Context: ...`` 2. UsetxFactory
to Construct and Serialise the Transaction: Use `txFactory` to con...
Near line 279: Usually, there’s no comma before “if”.
Context: ...ts directly to broadcast the transaction, if you wish so.
Path-based Instructions (1)
docs/learn/advanced/01-transactions.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
2. Use `txFactory` to Construct and Serialise the Transaction: | ||
Use `txFactory` to configure and sign the transaction. | ||
|
||
```go | ||
// initialise `txFactory` with configuration | ||
txFactory := txConfig.NewFactory(). | ||
WithChainID("your-chain-id"). | ||
WithKeybase(keyring). | ||
WithSignMode(signing.SignMode_SIGN_MODE_TEXTUAL) | ||
|
||
// create a new transaction builder with factory | ||
txBuilder := txFactory.NewTxBuilder() | ||
|
||
// set the message using the parsed JSON data | ||
msg := &tx.MsgSend{ | ||
FromAddress: jsonTx.FromAddress, | ||
ToAddress: jsonTx.ToAddress, | ||
Amount: jsonTx.Amount, | ||
} | ||
txBuilder.SetMsgs(msg) | ||
txBuilder.SetMemo(jsonTx.Memo) | ||
txBuilder.SetFeeAmount(jsonTx.Amount) | ||
txBuilder.SetGasLimit(200000) | ||
|
||
err := authclient.SignTx(txFactory, clientCtx, "moniker", txBuilder, false, true) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// get the serialised transaction bytes | ||
txBytes, err := txConfig.TxEncoder()(txBuilder.GetTx()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// convert to Base64 | ||
txBase64 := base64.StdEncoding.EncodeToString(txBytes) | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistency in terminology.
- Use `txFactory` to Construct and Serialise the Transaction:
+ Use `txFactory` to Construct and Serialize the Transaction:
The document uses American English spelling ("serialize"), so it's important to maintain this consistency throughout the document to avoid confusion.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
2. Use `txFactory` to Construct and Serialise the Transaction: | |
Use `txFactory` to configure and sign the transaction. | |
```go | |
// initialise `txFactory` with configuration | |
txFactory := txConfig.NewFactory(). | |
WithChainID("your-chain-id"). | |
WithKeybase(keyring). | |
WithSignMode(signing.SignMode_SIGN_MODE_TEXTUAL) | |
// create a new transaction builder with factory | |
txBuilder := txFactory.NewTxBuilder() | |
// set the message using the parsed JSON data | |
msg := &tx.MsgSend{ | |
FromAddress: jsonTx.FromAddress, | |
ToAddress: jsonTx.ToAddress, | |
Amount: jsonTx.Amount, | |
} | |
txBuilder.SetMsgs(msg) | |
txBuilder.SetMemo(jsonTx.Memo) | |
txBuilder.SetFeeAmount(jsonTx.Amount) | |
txBuilder.SetGasLimit(200000) | |
err := authclient.SignTx(txFactory, clientCtx, "moniker", txBuilder, false, true) | |
if err != nil { | |
panic(err) | |
} | |
// get the serialised transaction bytes | |
txBytes, err := txConfig.TxEncoder()(txBuilder.GetTx()) | |
if err != nil { | |
panic(err) | |
} | |
// convert to Base64 | |
txBase64 := base64.StdEncoding.EncodeToString(txBytes) | |
``` | |
2. Use `txFactory` to Construct and Serialize the Transaction: | |
Use `txFactory` to configure and sign the transaction. | |
```go | |
// initialise `txFactory` with configuration | |
txFactory := txConfig.NewFactory(). | |
WithChainID("your-chain-id"). | |
WithKeybase(keyring). | |
WithSignMode(signing.SignMode_SIGN_MODE_TEXTUAL) | |
// create a new transaction builder with factory | |
txBuilder := txFactory.NewTxBuilder() | |
// set the message using the parsed JSON data | |
msg := &tx.MsgSend{ | |
FromAddress: jsonTx.FromAddress, | |
ToAddress: jsonTx.ToAddress, | |
Amount: jsonTx.Amount, | |
} | |
txBuilder.SetMsgs(msg) | |
txBuilder.SetMemo(jsonTx.Memo) | |
txBuilder.SetFeeAmount(jsonTx.Amount) | |
txBuilder.SetGasLimit(200000) | |
err := authclient.SignTx(txFactory, clientCtx, "moniker", txBuilder, false, true) | |
if err != nil { | |
panic(err) | |
} | |
// get the serialised transaction bytes | |
txBytes, err := txConfig.TxEncoder()(txBuilder.GetTx()) | |
if err != nil { | |
panic(err) | |
} | |
// convert to Base64 | |
txBase64 := base64.StdEncoding.EncodeToString(txBytes) |
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
"mode": "BROADCAST_MODE_UNSPECIFIED" | ||
} | ||
``` | ||
|
||
#### CometBFT RPC | ||
|
||
The three methods presented above are actually higher abstractions over the CometBFT RPC `/broadcast_tx_{async,sync,commit}` endpoints, documented [here](https://docs.cometbft.com/v1.0/explanation/core/rpc). This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction, if you wish so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve sentence structure for better flow.
- This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction, if you wish so.
+ This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction if you wish.
Removing the comma before "if" and the unnecessary "so" at the end of the sentence can make the instruction clearer and more direct.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
The three methods presented above are actually higher abstractions over the CometBFT RPC `/broadcast_tx_{async,sync,commit}` endpoints, documented [here](https://docs.cometbft.com/v1.0/explanation/core/rpc). This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction, if you wish so. | |
The three methods presented above are actually higher abstractions over the CometBFT RPC `/broadcast_tx_{async,sync,commit}` endpoints, documented [here](https://docs.cometbft.com/v1.0/explanation/core/rpc). This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction if you wish. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (7)
docs/learn/advanced/01-transactions.md (7)
Line range hint
91-91
: Consider adding a preposition for clarity.- no need an additional step to gather other signers + no need for an additional step to gather other signers
Line range hint
97-97
: Add a comma before 'and' to connect two independent clauses.- hardware wallets and it is included in the v0.50 release. + hardware wallets, and it is included in the v0.50 release.
Line range hint
97-97
: Consider adding a comma for better readability.- displayed in its entirety even on small devices like the Ledger Nano. + displayed in its entirety, even on small devices like the Ledger Nano.
Line range hint
107-107
: Use "cannot" instead of "can not" for a more formal tone.- While we can not accept the implementation of the sign mode + While we cannot accept the implementation of the sign mode
Line range hint
127-127
: Use "An" instead of "A" before words that start with a vowel sound.- A SDK app router + An SDK app router
Line range hint
143-147
: Consider removing unnecessary commas in list items for consistency.- * `GasLimit`, option chosen by the users for how to calculate how much gas they will need to pay. - * `Memo`, a note or comment to send with the transaction. - * `FeeAmount`, the maximum amount the user is willing to pay in fees. - * `TimeoutHeight`, block height until which the transaction is valid. - * `Signatures`, the array of signatures from all signers of the transaction. + * `GasLimit` - option chosen by the users for how to calculate how much gas they will need to pay. + * `Memo` - a note or comment to send with the transaction. + * `FeeAmount` - the maximum amount the user is willing to pay in fees. + * `TimeoutHeight` - block height until which the transaction is valid. + * `Signatures` - the array of signatures from all signers of the transaction.
Line range hint
162-162
: Correct the spelling of "pseudo-code".- Here's a pseudo-code snippet of how to generate and encode a transaction + Here's a pseudocode snippet of how to generate and encode a transaction
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- docs/learn/advanced/01-transactions.md (1 hunks)
Additional Context Used
LanguageTool (13)
docs/learn/advanced/01-transactions.md (13)
Near line 91: Possible missing preposition found.
Context: ...ody` and their own signer info (no need an additional step to gather other signers...
Rule ID: AI_HYDRA_LEO_MISSING_OF
Near line 97: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...r signing experience on hardware wallets and it is included in the v0.50 release. In...
Rule ID: COMMA_COMPOUND_SENTENCE
Near line 97: Possible missing comma found.
Context: ... screen is meant to be displayed in its entirety even on small devices like the Ledger N...
Rule ID: AI_HYDRA_LEO_MISSING_COMMA
Near line 107: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... sign mode to the Cosmos-SDK. While we can not accept the implementation of the sign m...
Rule ID: CAN_NOT_PREMIUM
Near line 127: Use “An” instead of ‘A’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...d inside each module'stx.proto
file. A SDK app router automatically maps every...
Rule ID: EN_A_VS_AN
Near line 143: Loose punctuation mark.
Context: ...ncluded in the transaction. *GasLimit
, option chosen by the users for how to c...
Rule ID: UNLIKELY_OPENING_PUNCTUATION
Near line 144: Loose punctuation mark.
Context: ...much gas they will need to pay. *Memo
, a note or comment to send with the tran...
Rule ID: UNLIKELY_OPENING_PUNCTUATION
Near line 145: Loose punctuation mark.
Context: ...send with the transaction. *FeeAmount
, the maximum amount the user is willing ...
Rule ID: UNLIKELY_OPENING_PUNCTUATION
Near line 146: Loose punctuation mark.
Context: ...illing to pay in fees. *TimeoutHeight
, block height until which the transactio...
Rule ID: UNLIKELY_OPENING_PUNCTUATION
Near line 147: Loose punctuation mark.
Context: ...the transaction is valid. *Signatures
, the array of signatures from all signer...
Rule ID: UNLIKELY_OPENING_PUNCTUATION
Near line 162: This word is normally spelled as one.
Context: ...SIGN_MODE_LEGACY_AMINO_JSON`). Here's a pseudo-code snippet of how to generate and encode a...
Rule ID: EN_COMPOUNDS_PSEUDO_CODE
Near line 228: Do not mix variants of the same word (‘serialise’ and ‘serialize’) within a single text.
Context: ...`` 2. UsetxFactory
to Construct and Serialise the Transaction: Use `txFactory` to con...
Rule ID: EN_WORD_COHERENCY
Near line 279: Usually, there’s no comma before “if”.
Context: ...ts directly to broadcast the transaction, if you wish so.
Rule ID: IF_NO_COMMA
Markdownlint (1)
docs/learn/advanced/01-transactions.md (1)
94: Expected: 1; Actual: 2
Multiple consecutive blank lines
Path-based Instructions (1)
docs/learn/advanced/01-transactions.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
json.Unmarshal([]byte(jsonString), &jsonTx) | ||
``` | ||
|
||
2. Use `txFactory` to Construct and Serialise the Transaction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistency in terminology: use "serialize" throughout the document.
- Use `txFactory` to Construct and Serialise the Transaction:
+ Use `txFactory` to Construct and Serialize the Transaction:
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
2. Use `txFactory` to Construct and Serialise the Transaction: | |
2. Use `txFactory` to Construct and Serialize the Transaction: |
``` | ||
|
||
3. Provide the Base64 Encoded Transaction: | ||
The `tx_bytesz should be the base64 encoded string of txBytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `tx_bytesz should be the base64 encoded string of txBytes. | |
The `tx_bytes` should be the base64 encoded string of txBytes. |
1. Parse the JSON to Structs: | ||
Continue parsing the JSON string into Go structs as previously done. | ||
|
||
```go | ||
jsonString := `{ | ||
"from_address": "cosmos1...", | ||
"to_address": "cosmos1...", | ||
"amount": [{"denom": "stake", "amount": "50"}], | ||
"memo": "Test transaction" | ||
}` | ||
|
||
var jsonTx struct { | ||
FromAddress string `json:"from_address"` | ||
ToAddress string `json:"to_address"` | ||
Amount []tx.Coin `json:"amount"` | ||
Memo string `json:"memo"` | ||
} | ||
json.Unmarshal([]byte(jsonString), &jsonTx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It says "as previously done", but I don't see any other example doing this. I also don't think this is correct, the tx structure doesn't look right and the type tx.Coin
doesn't exist in the SDK (or at least we don't usually use tx.
with it).
Later also tx.MsgSend
is used, which should use a more familiar import path for bank types.
Description
A old issue, which people keep getting held up on. The documentation shows with examples how to construct a tx in the correct flow for
/cosmos/tx/v1beta1/txs
endpointCloses: #11625
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
Summary by CodeRabbit
/cosmos/tx/v1beta1/txs
endpoint.