This library represents the sollution of the task, that follows. You can find the resulting contract deloyed on testnet here
use.sh - the main file to run the methods of the library
src/contracts/ - you can find FunC code of the contracts here
compile-counter-contract-minter.fif - mint script for counter-contract-minter with counter-contract in the storage
compile-counter.fif - compilation script to deploy an individual counter off-chain
external-to-wallet.fif - script to interact with deploy-wallet
get-addr-from-file.fif - a small script to get the address of deploy wallet from file for futher interactions
new-wallet.fif - a script to mint a new deploy-wallet
change-counter-admin.fif - a message body pattern for a message to change counter admin address
Implement a proxy that count transactions
Description: Implement a system of smart contracts that count how many times users send a payments to a certain user, and route the payment to the owner of the smart contract(s). A payment, to be accepted, should have an arbitrary body (empty is OK) and msg_value greater than 0.1 TON. For user perspective, the contract should work fine with normal transfers from common TON Wallets. For any user, the recipient should be always the same.
Requirements:
- the admin of the proxy should be able to change the admin address (using opcode = 1)
- contracts should have a way to check the number of transaction per each user via get-calls (offchain)
- the fees must be linear
- the system is workchain specific and should work only in basechain
- if a payment is rejected (eg msg_value < 0.1ton), the ton should be sent back to the user
- the contract should work on his own, without any kind of backend or frontend
eta: 2 days
Please use bash version 3.2.57(1)-release to execute this lib.
Download nessesary TON pre-build here and change directories to lite-client, fift and func compilers on lines 6-8 of shell_config.sh as follows:
path_to_func_binaries=YOUR_PATH # func
path_to_fift_binaries=YOUR_PATH # fift
path_to_lite_client_binaries=YOUR_PATH # lite-client
First you need to compile your deploy wallet, that will send internal messages to other smart-contracts and load coins on them. After compiling the wallet you will find files with private key, wallet address and resulting BOC-file that we will send to blockchain on deploy in the directory src/build/wallet/
Example:
./use.sh compile-wallet
Load coins to the address of your future deploy-wallet using Testnet TON Wallet in testnet and TON Wallet, Tonkeeper or Tonhub in mainnet.
You will find the address of your future wallet (where you need to send coins) in the output of the terminal after making the previous step. Search a line in output like this:
new wallet address = COPY_ADDRESS_THAT_WILL_BE_HERE
Use command below to deploy wallet:
./use.sh deploy-wallet [net]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
Example:
./use.sh deploy-wallet testnet
- Deploy-wallet will deploy contracts and send messages
- Counter-contracts is a smart-contract of particular counter that has admin_addr and counter_num in it's storage
- Counter-contract-minter is a smart-contract that is able to mint counter-contracts on-chain and has counter-contract code in it's storage
Note that you will run the spript ./use.sh to run all methods
This pattern will compile both counter-contract and counter-contract-minter, create a BOC-query for minting counter-contract-minter, and send BOC to blockchain. You can get the address of the newly deployed contract in the output.
./use.sh deploy-counter-minter [net]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
Example:
./use.sh deploy-counter-minter testnet
In order to create your personal counter just send any amount more that 0.1 TON on counter-contract-minter. It will mint a new counter with the sender's address as an admin.
Use the following pattern to get the number inside the storage of the spicific counter.
./use.sh get-counter-num [net] [counter_addr]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
[counter_addr] | The address of the specific counter that you want to invoke a get-method of |
Example:
./use.sh get-counter-num testnet EQCJ7ePEjkAS08EGrxP_qyKjZiBLo2qhiv0g3oyppDFy6tnk
Use the following pattern to get the slice with admin_addr inside the storage of the spicific counter. Note that it will be passed as 256-bit integer.
./use.sh get-counter-admin [net] [counter_addr]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
[counter_addr] | The address of the specific counter that you want to invoke a get-method of |
Example:
./use.sh get-counter-admin testnet EQCJ7ePEjkAS08EGrxP_qyKjZiBLo2qhiv0g3oyppDFy6tnk
Although this is a fully decentralized system, you can manually deploy a counter off-chain. For instance, you can do this to test change-counter-admin function with message generated automatically.
Use the pattern below to deploy a counter-contract off-chain.
./use.sh deploy-counter [net] [admin_addr] [counter_num]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
[admin_addr] | The admin of the counter |
[counter_num] | The initial number of the counter in it's storage, e.g. you can put 0 |
Example:
./use.sh deploy-counter testnet EQD57OL7n9KjwN5vxrW5KOJ-WIQTEw85mSMXmkdcSS_eLzi7 0
Use the pattern below to change the admin of the specific counter. Note that deploy-wallet shoul be the admin of this counter, as just him has the access to this function.
./use.sh change-counter-admin [net] [counter_addr] [new_admin_addr]
Argument | Description |
---|---|
[net] | Stipulate "testnet" or "mainnet" |
[counter_addr] | The address of the specific counter that you want to invoke a get-method of |
[new_admin_addr] | The new admin of the counter. Note that the rest amount of the message will be forwarded to him |
Example:
./use.sh change-counter-admin testnet EQCJ7ePEjkAS08EGrxP_qyKjZiBLo2qhiv0g3oyppDFy6tnk EQD57OL7n9KjwN5vxrW5KOJ-WIQTEw85mSMXmkdcSS_eLzi7