-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
A memory
field in the global state of the CLI allows you to store data long-term.
When using the script blocks feature, you execute script blocks. However, the args
field for script blocks get erased after each execution to keep them isolated and repeatable. But in some cases, you might want to store an account ID or contract ID for later reuse or reference. The same is true for data coming from Hardhat script execution.
Solution
Implementation:
stateController
that can be accessed anywhere.
/**
* Store data in memory
* @param {string} key - The key to store the data under
* @param {any} value - The value to store
*/
const saveToMemory = (key: string, value: any) => {
const memory = state.get('memory');
memory[key] = value;
saveKey('memory', memory);
};
/**
* Get data from memory
* @param {string} key - The key to retrieve the data from
* @returns {any} - The value stored under the key, or undefined if not found
*/
const getFromMemory = (key: string) => {
const memory = state.get('memory');
return memory[key];
};
Alternatives
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request