2021-02-22 17:48:14 +00:00
## Dero Stargate DVM Smart Contracts guide to install and test various function of private token Smart Contract.
2021-02-24 08:48:13 +00:00
**Notes:**
1] All wallet Addressess need to be registerd first with SC before they need to interact with. This condition will be removed in future.
2021-02-24 09:01:58 +00:00
2] Requirement of detoAnyRandomAddressFromExplorer during SC invocation will be removed in future.
3] **burn** is equal to deposit if SCID is defined else DERO/token will dissappear/burn from network forever. burn will renamed to something more meaningful. This can be proved with cryptographic proof.
2021-02-24 08:42:33 +00:00
2021-02-24 16:18:51 +00:00
**Download** Dero Stargate testnet [source ](https://github.com/deroproject/derohe ) and [binaries ](https://github.com/deroproject/derohe/releases ).
2021-02-22 17:48:14 +00:00
**Start Dero daemon in testnet mode.**
```
./derod-linux-amd64 --testnet
```
**Start Dero wallet in testnet.**
```
dero-wallet-cli-linux-amd64 --rpc-server --wallet-file testnet.wallet --testnet
```
**Start Dero wallet second instance to test transfer/ownership functions etc.**
```
dero-wallet-cli-linux-amd64 --wallet-file testnet2.wallet --testnet --rpc-server --rpc-bind=127.0.0.1:40403
```
**Dero testnet Explorer, Not required but if you want to host your own explorer for privacy reasons.**
```
./explorer-linux-amd64 --http-address=0.0.0.0:8080
```
Connect to explorer using browser on localhost:8080
**Dero Stargate Testnet Explorer**
[https://testnetexplorer.dero.io/ ](https://testnetexplorer.dero.io/ )
**To send DERO to multiple users in one transaction**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":100000,"destination":"deto1ADDRESS1"},{"amount":300000,"destination":"deto1ADDRESS12}] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**DERO has 2 types of SCs, public and private.**
1. Public SCs are public with all data/code/exchanges are public.
1. Private SCs have their smart contract data public. But no one knows how many tokens a particular user own or how much is he sending or how much is he receiving. Best example is to understand private SCs as banks and private tokens as cash. Once cash is out from the bank, Bank doesn't know "who has what amount or how is it being used/sent/received etc.". This makes all private tokens completely private.
**Installing Private Smart Contract.**
[Download token.bas ](https://git.dero.io/DeroProject/derosuite_stargate/src/master/cmd/dvm/token.bas )
```
curl --request POST --data-binary @token .bas http://127.0.0.1:40403/install_sc
```
**To check private token balance in wallet, type this command in wallet.**
```
balance SCID
```
**Download SC Code,check SC balance and variables from chain**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40402/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"getsc","params":{ "scid":"YourSCID" , "code":true}}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Examples of various private token Smart Contract functions**
**Eg: To send private tokens from one wallet to another wallet, this does not involve SC**
**Eg: this also showcases to send multiple assets( DERO and other tokens on DERO Network) within a single transaction**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":1,"destination":"DEROReceiverWalletAddress"},{"amount":1,"destination":"TokenReceiverWalletAddress","scid": "SCIDofToken" }] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
2021-02-24 08:42:33 +00:00
**Eg: Convert DERO to tokens 1:1 swap, we are swapping 44 DERO atomic units(DERI) to get some tokens**
2021-02-22 17:48:14 +00:00
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{"transfers":[{"amount":1,"destination":"detoAnyRandomAddressFromExplorer", "burn":44}],"scid":"aacaa7bb2388d06e523e5bc0783e4e131738270641406c12978155ba033373af", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"IssueTOKENX"}] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Convert tokens to DERO 1:1 swap, we are swapping 9 token atomic units to get 9 DERO atomic units**
2021-02-24 08:42:33 +00:00
**This tx shows transferring tokens natively, no dero fees etc, this is under evaluation,**
2021-02-22 17:48:14 +00:00
**Currently these show as coinbase rewards **
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{"transfers":[{"scid":"SCID", "amount":1,"destination":"detoAnyRandomAddressFromExplorer", "burn":9}],"scid":"YourSCID", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"ConvertTOKENX"}] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Eg: To withdraw balance only for smart contract owner**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":1,"destination":"detoAnyRandomAddressFromExplorer"}],"scid":"YourSCID", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"Withdraw"}, {"name":"amount","datatype":"U","value":2 }] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Eg: To transfer ownership of smart contract to new address/owner**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":1,"destination":"detoAnyRandomAddressFromExplorer"}],"scid":"YourSCID", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"TransferOwnership"}, {"name":"newowner","datatype":"S","value":"detoAddressForOwnershipReceiver" }] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Eg: To claim ownership of smart contract**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":1,"destination":"detoAnyRandomAddressFromExplorer"}],"scid":"YourSCID", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"ClaimOwnership"}] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
```
**Eg: To update smart contract code**
```
2021-02-24 08:42:33 +00:00
curl http://127.0.0.1:40403/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{ "transfers":[{"amount":1,"destination":"detoAnyRandomAddressFromExplorer"}],"scid":"YourSCID", "sc_rpc":[{"name":"entrypoint","datatype":"S","value":"UpdateCode"}, {"name":"code","datatype":"S","value":"new code should be placed here" }] }}' -H 'Content-Type: application/json'
2021-02-22 17:48:14 +00:00
2021-02-24 08:42:33 +00:00
```