UNPKG

starknet-devnet

Version:
65 lines (64 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Postman = void 0; function numericToHexString(numeric) { return "0x" + BigInt(numeric).toString(16); } /** * https://0xspaceshard.github.io/starknet-devnet/docs/postman */ class Postman { constructor(rpcProvider) { this.rpcProvider = rpcProvider; } /** * https://0xspaceshard.github.io/starknet-devnet/docs/postman#flush */ async flush(additionalArgs = { dryRun: false }) { return this.rpcProvider.sendRequest("devnet_postmanFlush", { dry_run: additionalArgs.dryRun, }); } /** * If `address` specified, tries to load an L1 messaging contract from that address. * If `address` omitted, deploys a new messaging contract by relying on the first predeployed * account of the L1 network specified with `networkUrl`, assuming default mnemonic seed. * If this predeployed account assumption does not hold, you should specify the private key * of the account to be used in `deployerAccountPrivateKey`. * More info in: https://0xspaceshard.github.io/starknet-devnet/docs/postman#load */ async loadL1MessagingContract(networkUrl, messagingContractAddress, deployerAccountPrivateKey) { if (!!messagingContractAddress && !!deployerAccountPrivateKey) { throw new Error("Both parameters cannot be specified simulatenously: `address`, `deployer_account_private_key`"); } return await this.rpcProvider.sendRequest("devnet_postmanLoad", { messaging_contract_address: messagingContractAddress, network_url: networkUrl, deployer_account_private_key: deployerAccountPrivateKey, }); } /** * https://0xspaceshard.github.io/starknet-devnet/docs/postman#mock-transactions */ async sendMessageToL2(l2ContractAddress, entryPointSelector, l1ContractAddress, payload, nonce, paidFeeOnL1) { return await this.rpcProvider.sendRequest("devnet_postmanSendMessageToL2", { l2_contract_address: l2ContractAddress, entry_point_selector: entryPointSelector, l1_contract_address: l1ContractAddress, payload: payload.map(numericToHexString), nonce: numericToHexString(nonce), paid_fee_on_l1: numericToHexString(paidFeeOnL1), }); } /** * https://0xspaceshard.github.io/starknet-devnet/docs/postman#l2-l1 */ async consumeMessageFromL2(fromAddress, toAddress, payload) { return await this.rpcProvider.sendRequest("devnet_postmanConsumeMessageFromL2", { from_address: fromAddress, to_address: toAddress, payload: payload.map(numericToHexString), }); } } exports.Postman = Postman;