The way to change the state of Nine Chronicles’ blockchain is to issue a transaction.
Transaction
A transaction in Libplanet
contains an action that changes the state on the blockchain network, and Nine Chronicles issues one transaction with one action.[1]
Action
Actions contain the arguments needed to change the state and the method that actually changes the state, and there are many types of actions defined in Nine Chronicles.[2]
Mead
Mead is the basic currency needed to execute actions, and the way to get it is through the Pledge system. For more information, check out this article.
Get Balance:
- Currency: Lib9c.Currencies.Mead
- Balance Address: Use the address of agent as it is.
public FungibleAssetValue? GetMead(IWorld world, Address address)
{
CurrencyAccount currencyAccount = world.GetCurrencyAccount(currency);
return currencyAccount.GetBalance(address, currency);
// or
Currency currency = Currencies.Mead;
return world.GetBalance(address, currency);
}
Action Point
Some actions require a resource called Action Point to perform. These points are maxed out at 120 [3] when you create your avatar, and can then be earned through [Patrol Rewards] (https://docs.nine-chronicles.com/introduction/intro/game-contents/patrol-rewards), AP Potion [4], and more.
Get State:
- Account Address: Nekoyume.Addresses.ActionPoint
- State Address: Use the address of your avatar as it is.
public int? GetActionPoint(IWorld world, Address address)
{
IAccount account = world.GetAccount(Addresses.ActionPoint);
if (account is null)
{
return null;
}
IValue state = account.GetState(address);
return state switch
{
Bencodex.Types.Integer i => i,
_ => null,
};
}
In the Nekoyume.Blockchain.Policy.BlockPolicySource.ValidateNextBlockTxRaw method of
Lib9c
, we are checking that a transaction contains only one action. ↩︎Check out the actions defined in the Nekoyume.Action namespace in
Lib9c
. ↩︎The maximum number of action points is defined as
120
in Nekoyume.Action.DailyReward.ActionPointMax. ↩︎An item that fills your AP to the maximum. ↩︎