speculative_exec

The speculative_exec endpoint allows contract developers to test and debug their contracts against the live network using real production data.

  • Note: speculative_exec executes a Deploy at a specified block.

This method will use 150 Compute Units.


Reference: Here

Parameters

  1. block_identifier [object] [optional]. The block hash or height on top of which to execute the deploy. If not supplied, the most recent block will be used.

  2. deploy [object] A Deploy consists of an item containing a smart contract along with the requester's signature(s).

{
	"id": -573285493134384228,
	"jsonrpc": "2.0",
	"method": "speculative_exec",
	"params": {
		"deploy": {
			"hash": "9d1f8eb023d61333b9053e95487d5f9215d05af91f68a35258a2fc315e58c79e",
			"header": {
				"ttl": "30m",
				"account": "01f03bbc42a3d5901c7232987ba84ab2c6d210973a0cfe742284dcb1d8b4cbe1c3",
				"body_hash": "2ae593f71142f5e20a1af3e9cae69c9455a28299a55608c7afae0fe0a3c087f6",
				"gas_price": 1,
				"timestamp": "2024-05-29T11:27:49.544Z",
				"chain_name": "casper",
				"dependencies": []
			},
			"payment": {
				"ModuleBytes": {
					"args": [
						[
							"amount",
							{
								"bytes": "0400ca9a3b",
								"parsed": "1000000000",
								"cl_type": "U512"
							}
						]
					],
					"module_bytes": ""
				}
			},
			"session": {
				"StoredContractByHash": {
					"args": [
						[
							"account",
							{
								"bytes": "4000000043333536303944444232464237373144454335423730344546424533433946374245413132373346333543334230314633433037343132394243433246344345",
								"parsed": "C35609DDB2FB771DEC5B704EFBE3C9F7BEA1273F35C3B01F3C074129BCC2F4CE",
								"cl_type": "String"
							}
						],
						[
							"balance",
							{
								"bytes": "758f000000000000",
								"parsed": 36725,
								"cl_type": "I64"
							}
						]
					],
					"hash": "d16aa9c6a7dc03d0f422eafeb244dcc782a3b7372bc2b2245c4e04f9c93f3e8f",
					"entry_point": "change_balance"
				}
			},
			"approvals": [
				{
					"signer": "01f03bbc42a3d5901c7232987ba84ab2c6d210973a0cfe742284dcb1d8b4cbe1c3",
					"signature": "011e0b5c36719206ee181c802befa2a0e42c0ad5a7dca143dff98abebbc8c262be0b9c6bd3f33dcc9077938f427f409ae6d484bd6ea8f216af195649c0baaded04"
				}
			]
		}
	}
}

Returns

  • api_version String The RPC API version.

  • block_hash Object The Block hash on top of which the deploy was executed.

  • execution_result Object The map of Block hash to execution result.


{
	"jsonrpc": "2.0",
	"result": {
		"api_version": "1.5.6",
		"block_hash": "9e5ad0c52fed3b6e69f8f53a3f3a52fc5dbfda8308235b7c54b1c0cf2512af35",
		"execution_result": {
			"Success": {
				"effect": {
					"operations": [],
					"transforms": [
						{
							"key": "account-hash-6174cf2e6f8fed1715c9a3bace9c50bfe572eecb763b0ed3f644532616452008",
							"transform": "Identity"
						}
						...
					]
                },
                "transfers": [],
                "cost": "171914831"
            }
        }
    },
    "id": -573285493134384260
}

Note for using examples below:

  • speculative_exec executes a Deploy at a specified block. When you test one of the examples below it may be expired due to timestamp, you can find the latest deploys to use for Casper testnet here and mainnet here.

  • If you copy the Raw data from the cspr.live explorer, you will need to remove part of the Deploy object from "api_version"onwards in your request.

curl https://mainnet.casper.validationcloud.io/v1/<YOUR_API_KEY_HERE> \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
	"id": -573285493134384228,
	"jsonrpc": "2.0",
	"method": "speculative_exec",
	"params": {
		"deploy": {
			"hash": "9d1f8eb023d61333b9053e95487d5f9215d05af91f68a35258a2fc315e58c79e",
			"header": {
				"ttl": "30m",
				"account": "01f03bbc42a3d5901c7232987ba84ab2c6d210973a0cfe742284dcb1d8b4cbe1c3",
				"body_hash": "2ae593f71142f5e20a1af3e9cae69c9455a28299a55608c7afae0fe0a3c087f6",
				"gas_price": 1,
				"timestamp": "2024-05-29T11:27:49.544Z",
				"chain_name": "casper",
				"dependencies": []
			},
			"payment": {
				"ModuleBytes": {
					"args": [
						[
							"amount",
							{
								"bytes": "0400ca9a3b",
								"parsed": "1000000000",
								"cl_type": "U512"
							}
						]
					],
					"module_bytes": ""
				}
			},
			"session": {
				"StoredContractByHash": {
					"args": [
						[
							"account",
							{
								"bytes": "4000000043333536303944444232464237373144454335423730344546424533433946374245413132373346333543334230314633433037343132394243433246344345",
								"parsed": "C35609DDB2FB771DEC5B704EFBE3C9F7BEA1273F35C3B01F3C074129BCC2F4CE",
								"cl_type": "String"
							}
						],
						[
							"balance",
							{
								"bytes": "758f000000000000",
								"parsed": 36725,
								"cl_type": "I64"
							}
						]
					],
					"hash": "d16aa9c6a7dc03d0f422eafeb244dcc782a3b7372bc2b2245c4e04f9c93f3e8f",
					"entry_point": "change_balance"
				}
			},
			"approvals": [
				{
					"signer": "01f03bbc42a3d5901c7232987ba84ab2c6d210973a0cfe742284dcb1d8b4cbe1c3",
					"signature": "011e0b5c36719206ee181c802befa2a0e42c0ad5a7dca143dff98abebbc8c262be0b9c6bd3f33dcc9077938f427f409ae6d484bd6ea8f216af195649c0baaded04"
				}
			]
		}
	}
}'

Last updated