This standard will describe the variables and methods needed to create a basic token on the Lamden Blockchain. Adherence to this standard ensures highest possible compatibility for your token.
Discussion on finalizing this standard is taking place in the Github Discussions; With a current deadline of March 2nd, 2021. Anyone is welcome to join and comment.
none
This variable holds the main account balances for the contract balances[account]
.
It also uses a multi-hash to store allowances balances[owner, spender]
.
- Type:
Hash
- default value:
0
- default value:
- Required:
True
balances = Hash(default_value=0)
This is the constructor method for smart contract. We will use it to mint an initial token supply.
This method is not required
. The below example is included to show how you might mint an initial supply to an account.
- Decorator: @construct
- Required:
False
- Public:
False
- arguments:
vk
- type:
string
- description: The account provided will be minted the initial supply of tokens.
- type:
- state changes:
1
- assertions:
none
- return:
void
@construct
def seed(vk: str):
balances[vk] = 1_000_000
This is the main transfer method for the token.
This should only be called if the caller
is sending their tokens directly.
To send tokens on behalf of another account use the transfer_from
method.
- Decorator:
@export
- Public:
True
- arguments:
amount
- type:
float
- The amount of tokens to be transferred
- type:
to
- type:
string
- The account to send the tokens to.
- type:
- state changes:
2
- assertions:
amount
must be greater-than 0- error:
Cannot send negative balances!
- error:
callers
token balance must be greater-than or equal toamount
- error:
Not enough coins to send!
- error:
- return:
void
@export
def transfer(amount: float, to: str):
assert amount > 0, 'Cannot send negative balances!'
assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
# remove amount from senders account
balances[ctx.caller] -= amount
# add amount to receivers account
balances[to] += amount
This method will return add to the approval balance of the caller's account for the to
address provided.
- Decorator:
@export
- Public:
True
- arguments:
amount
- type:
float
- The amount of approval to add to the
to
account
- type:
to
- type:
string
- The account that will receive the approval amount
- type:
- state changes:
2
- assertions:
amount
must be greater-than 0- error:
Cannot send negative balances!
- error:
- return:
void
@export
def approve(amount: float, to: str):
assert amount > 0, 'Cannot send negative balances!'
# Add the amount to the callers
balances[ctx.caller, to] += amount
This method will allow a caller to spend tokens from another account.
For this to work a prior call to approve
is needed by the main_account
to set an allowance
for the caller.
Failure to set an allowance beforehand will cause the method to error.
- Decorator:
@export
- Public:
True
- arguments:
amount
- type:
float
- The amount of tokens to transfer from
main_account
- type:
to
- type:
string
- The account that the tokens will be sent to
- type:
main_account
- type:
string
- The account the tokens will taken from
- type:
- state changes:
3
- assertions:
amount
must be greater-than 0- error:
Cannot send negative balances!
- error:
caller
has an approval greater-than or equal to the transferamount
- error:
Not enough coins approved to send! You have X and are trying to spend X
- error:
- the token balance of
main_account
is greater-than or equal to the transferamount
- error:
Not enough coins to send!
- error:
- return:
void
@export
def transfer_from(amount: float, to: str, main_account: str):
assert amount > 0, 'Cannot send negative balances!'
assert balances[main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
.format(balances[main_account, ctx.caller], amount)
assert balances[main_account] >= amount, 'Not enough coins to send!'
# reduce the approval amount by the amount being spent
balances[main_account, ctx.caller] -= amount
# remove amount spent from the main account
balances[main_account] -= amount
# add the amount spent to the receivers account
balances[to] += amount