Simulate a transaction for estimating gas usage.
Parameters
tx
- The processable content of the transaction.
Object Name | Required | Type | Detail |
---|---|---|---|
messages | ✅ | Array | A list of messages to be executed. The signers of the messages define the number and order of auth_info 's signer_infos and signatures . By convention, the first signer (usually the first message) is referred to as the primary signer and pays the fee for the whole transaction. |
memo | ❌ | String | Any arbitrary memo to be added to the transaction |
timeout_height | ✅ | String | The block height after which this transaction will not be processed by the chain |
extension_options | ❌ | Array | Arbitrary options that can be added by chains when the default options are not sufficient. If any of these are present and can't be handled, the transaction will be rejected. |
non_critical_extension_options | ❌ | Array | Arbitrary options that can be added by chains when the default options are not sufficient. If any of these are present and can't be handled, they will be ignored. |
fee | ✅ | Object | The transaction gas amount. |
signature | ✅ | Object | The signature of the transaction. Contains the client pub_key , account_number , sequence |
auth_info
- The authorization related content of the transaction, specifically signers, signer modes and fee.
Key | Required | Type | Detail |
---|---|---|---|
signer_info | ✅ | Object | The signing modes for the required signers. The number and order of elements must match the required signers from tx 's messages |
fee | ✅ | Object | The fee and gas limit for the transaction. The first signer is the primary signer and the one which pays the fee. |
signatures
- A list of signatures
Key | Required | Type | Detail |
---|---|---|---|
signatures | ✅ | Array | A list of signatures that matches the length and order of auth_info 's signer_info |
{
"tx": {
"body": {
"messages": [{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "cosmos1f7nwjfrks5zpaguugerjtgp2eh6fuqd0939fe2",
"to_address": "cosmos1u4pg3qxgr8dw8k3t2lm2xz7f2zcjyehw8neckl",
"amount": [{
"denom": "uatom",
"amount": "50000"
}]
}],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [{
"public_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A+WiqxAgJ/fFviFCOzozjwruYy1KseuI0j/hzkJ/z2jH"
},
"mode_info": {
"single": {
"mode": "SIGN_MODE_LEGACY_AMINO_JSON"
}
},
"sequence": "1"
}],
"fee": {
"amount": [{
"denom": "uatom",
"amount": "2000"
}],
"gas_limit": "80000",
"payer": "",
"granter": ""
}
},
"signatures": ["+GbfnijcDQV96uvIJD0Ks+68bWl4aK6QR496KeBcheUx4ZOviZlaVHRBCsLOQLKy94+VJv5Ip6SEhcUEgus5eA=="]
}
}
Result
The transaction information.
Example
Request
curl <your-rest-endpoint>/cosmos/tx/v1beta1/simulates \
-X POST \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{"tx": {"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1f7nwjfrks5zpaguugerjtgp2eh6fuqd0939fe2","to_address":"cosmos1u4pg3qxgr8dw8k3t2lm2xz7f2zcjyehw8neckl","amount":[{"denom":"uatom","amount":"50000"}]}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[{"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A+WiqxAgJ/fFviFCOzozjwruYy1KseuI0j/hzkJ/z2jH"},"mode_info":{"single":{"mode":"SIGN_MODE_LEGACY_AMINO_JSON"}},"sequence":"1"}],"fee":{"amount":[{"denom":"uatom","amount":"2000"}],"gas_limit":"80000","payer":"","granter":""}},"signatures":["+GbfnijcDQV96uvIJD0Ks+68bWl4aK6QR496KeBcheUx4ZOviZlaVHRBCsLOQLKy94+VJv5Ip6SEhcUEgus5eA=="]}}'
Return
{
"gas_info": {
"gas_wanted": "0",
"gas_used": "61548"
},
"result": {
"data": "Ch4KHC9jb3Ntb3MuYmFuay52MWJldGExLk1zZ1NlbmQ=",
"log": "[{\"events\":[{\"type\":\"coin_received\",\"attributes\":[{\"key\":\"receiver\",\"value\":\"cosmos1u4pg3qxgr8dw8k3t2lm2xz7f2zcjyehw8neckl\"},{\"key\":\"amount\",\"value\":\"50000uatom\"}]},{\"type\":\"coin_spent\",\"attributes\":[{\"key\":\"spender\",\"value\":\"cosmos1f7nwjfrks5zpaguugerjtgp2eh6fuqd0939fe2\"},{\"key\":\"amount\",\"value\":\"50000uatom\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/cosmos.bank.v1beta1.MsgSend\"},{\"key\":\"sender\",\"value\":\"cosmos1f7nwjfrks5zpaguugerjtgp2eh6fuqd0939fe2\"},{\"key\":\"module\",\"value\":\"bank\"}]},{\"type\":\"transfer\",\"attributes\":[{\"key\":\"recipient\",\"value\":\"cosmos1u4pg3qxgr8dw8k3t2lm2xz7f2zcjyehw8neckl\"},{\"key\":\"sender\",\"value\":\"cosmos1f7nwjfrks5zpaguugerjtgp2eh6fuqd0939fe2\"},{\"key\":\"amount\",\"value\":\"50000uatom\"}]}]}]",
"events": [
{
"type": "message",
"attributes": [
{
"key": "YWN0aW9u",
"value": "L2Nvc21vcy5iYW5rLnYxYmV0YTEuTXNnU2VuZA==",
"index": false
}
]
},
{
"type": "coin_spent",
"attributes": [
{
"key": "c3BlbmRlcg==",
"value": "Y29zbW9zMWY3bndqZnJrczV6cGFndXVnZXJqdGdwMmVoNmZ1cWQwOTM5ZmUy",
"index": false
},
{
"key": "YW1vdW50",
"value": "NTAwMDB1YXRvbQ==",
"index": false
}
]
},
{
"type": "coin_received",
"attributes": [
{
"key": "cmVjZWl2ZXI=",
"value": "Y29zbW9zMXU0cGczcXhncjhkdzhrM3QybG0yeHo3ZjJ6Y2p5ZWh3OG5lY2ts",
"index": false
},
{
"key": "YW1vdW50",
"value": "NTAwMDB1YXRvbQ==",
"index": false
}
]
},
{
"type": "transfer",
"attributes": [
{
"key": "cmVjaXBpZW50",
"value": "Y29zbW9zMXU0cGczcXhncjhkdzhrM3QybG0yeHo3ZjJ6Y2p5ZWh3OG5lY2ts",
"index": false
},
{
"key": "c2VuZGVy",
"value": "Y29zbW9zMWY3bndqZnJrczV6cGFndXVnZXJqdGdwMmVoNmZ1cWQwOTM5ZmUy",
"index": false
},
{
"key": "YW1vdW50",
"value": "NTAwMDB1YXRvbQ==",
"index": false
}
]
},
{
"type": "message",
"attributes": [
{
"key": "c2VuZGVy",
"value": "Y29zbW9zMWY3bndqZnJrczV6cGFndXVnZXJqdGdwMmVoNmZ1cWQwOTM5ZmUy",
"index": false
}
]
},
{
"type": "message",
"attributes": [
{
"key": "bW9kdWxl",
"value": "YmFuaw==",
"index": false
}
]
}
]
}
}