examples.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Solang Solidity Examples
  2. ========================
  3. Here are two examples of Solidity contracts.
  4. General examples
  5. ----------------
  6. Flipper
  7. _______
  8. This is the `ink! flipper example <https://github.com/paritytech/ink/blob/v3.3.0/examples/flipper/lib.rs>`_
  9. written in Solidity:
  10. .. include:: ../examples/polkadot/flipper.sol
  11. :code: solidity
  12. Example
  13. _______
  14. A few simple arithmetic functions.
  15. .. include:: ../examples/example.sol
  16. :code: solidity
  17. Solana examples
  18. ---------------
  19. NFT example
  20. ___________
  21. There is an example on Solana's integration tests for a Solidity contract that manages an NFT. The contract is supposed
  22. to be the NFT itself. It can mint itself and transfer ownership. It also stores on chain information about itself, such as its URI.
  23. Please, check `simple_collectible.sol <https://github.com/hyperledger/solang/blob/main/integration/solana/simple_collectible.sol>`_
  24. for the Solidity contract and `simple_collectible.spec.ts <https://github.com/hyperledger/solang/blob/main/integration/solana/simple_collectible.spec.ts>`_
  25. for the Typescript code that interacts with Solidity.
  26. PDA Hash Table
  27. ______________
  28. On Solana, it is possible to create a hash table on chain with program derived addresses (PDA). This is done by
  29. using the intended key as the seed for finding the PDA. There is an example of how one can achieve so in our integration
  30. tests. Please, check `UserStats.sol <https://github.com/hyperledger/solang/blob/main/integration/solana/UserStats.sol>`_
  31. for the Solidity contract and `user_stats.spec.ts <https://github.com/hyperledger/solang/blob/main/integration/solana/user_stats.spec.ts>`_
  32. for the client code, which contains most of the explanations about how the table works. This example was inspired by
  33. `Anchor's PDA hash table <https://www.anchor-lang.com/docs/pdas#hashmap-like-structures-using-pd-as>`_.