Over the past week, I spent a substantial amount of development time on an upcoming contract to be launched at NEARCon. During this process, I ran into a slew of problems that led to a pretty bad developer experience.
The Problem
Currently, there is no way to query for the GAS price at runtime and there is also no way to query for data related to access keys belonging to your contract.
I understand that you cannot query for access key information for keys that belong to an arbitrary contract since that info might be stored in another shard. If the keys belong to your contract, I would imagine that this information could be queried at runtime (correct me if I’m wrong).
Specifically, I propose that the the following struct is queryable for keys belonging to the current contract account.
type KeyInformation = {
public_key: string,
access_key: {
nonce: number,
permission: FunctionCall | string // string being 'FullAccess' if the key is a full access key
}
}
type FunctionCall = {
allowance: string,
method_names: Array<string>,
}
3 functions should be exposed (the naming is subject to change):
-
env::keys_for_current_account(from_index: Option<string>, limit: Option<number>) -> Vector<KeyInformation>
which paginates through the keys belonging to the current account ID (contract). -
env::key_supply_for_current_account() -> number
which returns the total number of keys belonging to the current account ID. -
env::key_info_by_public_key_for_current_account(public_key: PublicKey) -> Option<KeyInformation>
which returns the key information for the specific public key passed in
In addition, as NEAR grows, the blocks might get congested and smart contracts might want to know the GAS price and act accordingly. I think adding a function to get the current GAS price at runtime is important as well.
-
env::gas_price
which returns how much yoctoNEAR it costs to purchase 1 GAS.
Use Case
For a real world example of why this would help, i’ll explain a use case. Imagine you have a contract that allows users to “purchase” function call access keys that can do different things. The user must pay for the access key allowance when the key is created. An example of this is the linkdrop contract.
When the key is used up / deleted, dApps might want to refund users for any allowance that was unspent. Currently, there is no way to do this. In addition, when creating the key, often times, the dev will know how much GAS will be attached to the function calls and they might want to dynamically calculate the pessimistic allowance that the key must have and to do this, they need the current GAS price.