L1-L2 interaction via Postman
Postman is a Starknet utility that allows testing L1-L2 interaction. It is unrelated to the Postman API platform. To use it, ensure you have:
- an L1 node (possibilities listed below)
- a Devnet instance (acting as L2 node)
- a loaded messaging contract
- this is an L1 contract for exchanging messages between L1 and L2
- you can deploy a new instance or specify the address of an old one
- an L1 contract that can interact with the messaging contract
- an L2 contract that can interact with the messaging contract
There are two internal message queues: one for L1->L2 messages, another for L2->L1 messages. When there are messages in a queue, you will need to flush to transmit the messages to their destinations.
You can use starknet-devnet-js to assist you in the above listed actions. This example, especially the it("should exchange messages between L1 and L2") test case should be of most help. The required contracts are configured and deployed in the before block. Alternatively, you can directly send requests to the endpoints specified below.
Load
// JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_postmanLoad",
"params": {
"network_url": "http://localhost:8545",
"messaging_contract_address": "0x123...def", // optional
"deployer_account_private_key": "0xe2ac...583f" // optional
}
}
Loads an L1 MockStarknetMessaging contract instance, potentially deploying a new one, which is used for message exchange between L1 and L2.
L1 network
The network_url parameter refers to the URL of the JSON-RPC API endpoint of the L1 node you've run locally, or which is publicly accessible. Possibilities include, but are not limited to:
Messaging contract deployment
Here's how the rest of the parameters should be used, depending on your L1 network:
- If your L1 network already has a messaging contract deployed that you wish to use, populate
messaging_contract_addresswith its address.- The provided address shall be checked by asserting that there indeed is contract code deployed at that address, without any ABI assertions.
- If your L1 network does not have such a contract, or you simplify wish to deploy a new instance, leave out the
messaging_contract_addressproperty.- If your L1 network is a local testnet (e.g. Anvil) with the default mnemonic seed and a default set of predeployed accounts, you don't have to specify anything else—a new messaging contract shall be deployed using a predeployed account.
- Otherwise (e.g. on the Sepolia testnet or an Anvil with a custom mnemonic seed) you are expected to populate
deployer_account_private_keywith the private key of a funded account. This property is not applicable ifmessaging_contract_addressis specified.
L1-L2 communication requires extra attention if Devnet is run in a Docker container. The network_url argument must be on the same network as Devnet. E.g. if your L1 instance is run locally (i.e. using the host machine's network), then:
- on Linux, it is enough to run the Devnet Docker container with
--network host - on Mac and Windows, replace any
http://localhostorhttp://127.0.0.1occurrence in the value ofnetwork_urlwithhttp://host.docker.internal.
Loading a messaging contract is a dumpable event, meaning that, if you've enabled dumping, a messaging-contract-loading event will be dumped. Keep in mind that, if you rely on Devnet deploying a new contract, i.e. if you don't specify a contract address of an already deployed messaging contract, a new contract will be deployed at a new address on each loading of the dump. Read more about dumping here.