Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Coins usage in smart contract #198

Open
Ben-Rey opened this issue Aug 12, 2023 · 4 comments
Open

Document Coins usage in smart contract #198

Ben-Rey opened this issue Aug 12, 2023 · 4 comments
Assignees

Comments

@Ben-Rey
Copy link
Contributor

Ben-Rey commented Aug 12, 2023

There seems to be confusion regarding the use of coins in smart contracts, whether it's for a function call or during deployment.

Some example of questions:

  • How are coins allocated for storage during a smart contract call?
  • Explain that there isn't a "payable" function.
  • Discuss coin allocation for deployment. Is it solely for storage?
  • What occurs when no more space is available? Who manages the storage, and who bears the cost?

@damip Please challenge the questions if they appear unclear or illogical.

@damip
Copy link
Member

damip commented Aug 28, 2023

Here are succinct responses that should be added to the docs.

Transferring coins

  • pure coin transfers are allowed (provided enough balance):
    • from any account the context has write access to
    • towards any account the context has write access to
    • towards any externally owned account
  • moving coins towards a smart contract account without having write access to it requires calling an exported function of that smart contract and setting the "coins" parameter of the call
    • at the beginning of the call, those coins are transferred to the called account
    • if the call fails, the coin transfer is rolled back
    • for now, all exported smart contract functions are considered payable in Massa which means that they can all be called with non-zero "coins"

Storage charges

When calling create_sc, two charges happen:

  • the caller of the create_sc is charged with 0.001 coins for the creation of a new ledger entry
  • the caller of the create_sc is charged with 0.0001 coins per byte of bytecode stored on the newly created SC

Space is always available because occupying space requires locking coins.
The available space is therefore naturally limited by the total supply of coins in circulation, but as long as you have coins you can always store.

Storage is paid by the address at the top of the call stack.
When storage bytes are freed, the unlocked coins are given to the address on top of the call stack.

@Ben-Rey
Copy link
Contributor Author

Ben-Rey commented Aug 29, 2023

Very clear thanks !

@Ben-Rey Ben-Rey self-assigned this Aug 29, 2023
@qdrn
Copy link
Contributor

qdrn commented Sep 3, 2023

It's a good opportunity to explain in which context accounts have write access.

@qdrn
Copy link
Contributor

qdrn commented Sep 3, 2023

Not directly related but in the previous documentation there was this document that was created which documented the stack https://github.com/massalabs/massa-docs/blob/main/web3-dev/smart-contracts/address-stack.rst.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants