near-config-loader
v1.0.0
Published
npm Package - near-config-loader
Readme
near-config-loader
Store and retrieve configuration objects on the NEAR blockchain.
Installation
npm install near-config-loader
API
loadConfig(contractId, configKey)
Reads a config object from the NEAR contract view function.
import { loadConfig } from 'near-config-loader';
const config = await loadConfig('mycontract.near', 'my-config-key'); console.log(config);
listConfigKeys(contractId)
Returns all config keys stored in the contract.
import { listConfigKeys } from 'near-config-loader';
const keys = await listConfigKeys('mycontract.near'); console.log(keys); // ['key1', 'key2']
buildAccount(accountId, keyPair, networkId?)
Creates a near-api-js Account instance ready for signing transactions.
import * as nearApiJs from 'near-api-js'; import { buildAccount } from 'near-config-loader';
const keyPair = nearApiJs.KeyPair.fromString('ed25519:...'); const account = await buildAccount('myaccount.near', keyPair, 'mainnet');
saveConfig(account, contractId, configKey, config)
Saves a config object to the contract.
import { saveConfig } from 'near-config-loader';
const result = await saveConfig(account, 'mycontract.near', 'my-config-key', { theme: 'dark', });
deleteConfig(account, contractId, configKey)
Deletes a config entry from the contract.
import { deleteConfig } from 'near-config-loader';
const txHash = await deleteConfig(account, 'mycontract.near', 'my-config-key');
License
MIT
