Skip to content

feat: state-init command#560

Open
pityjllk wants to merge 1 commit intonear:mainfrom
pityjllk:feat/state-init
Open

feat: state-init command#560
pityjllk wants to merge 1 commit intonear:mainfrom
pityjllk:feat/state-init

Conversation

@pityjllk
Copy link

Added a new contract state-init subcommand that initializes a deterministic account with a global contract and state data. The command supports two ways to reference the global contract: by code hash or by account ID. There are also 2 ways to provide the initial state data: reading hex-encoded key-value JSON from a file or passing it inline as a JSON string.

A few other things in this change:

  • If the deterministic account already exists on the network, the command skips sending the transaction entirely and just prints a message
  • Improved how the state init action is displayed before signing — the data map now shows formatted hex key-value pairs instead of a raw debug dump, and the code reference is shown more concisely (hash: ... / account ref: ...)
  • The derived deterministic account ID is now explicitly shown in the transaction summary before the user signs

@pityjllk pityjllk requested a review from a team as a code owner February 27, 2026 08:22
@github-project-automation github-project-automation bot moved this to NEW❗ in DevTools Feb 27, 2026
Comment on lines +3166 to +3169
let key = hex::decode(&k)
.map_err(|e| color_eyre::eyre::eyre!("Failed to hex-decode key '{k}': {e}"))?;
let value = hex::decode(&v)
.map_err(|e| color_eyre::eyre::eyre!("Failed to hex-decode value '{v}': {e}"))?;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to be consistent and encode as base64, as key-value pairs in near_sdk::StateInit and DeterministicAccountStateInitV1 are encoded as base64 as well

Comment on lines +104 to +115
pub enum Data {
#[strum_discriminants(strum(
message = "data-from-file - Read hex-encoded key-value JSON data from a file"
))]
/// Read hex-encoded key-value JSON data from a file
DataFromFile(DataFromFile),
#[strum_discriminants(strum(
message = "data-from-json - Provide hex-encoded key-value JSON data inline"
))]
/// Provide hex-encoded key-value JSON data inline
DataFromJson(DataFromJson),
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an option to provide the whole StateInit serialized as borsh and encoded as base64 as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: NEW❗

Development

Successfully merging this pull request may close these issues.

2 participants