freeton_wallet
freeton_wallet copied to clipboard
Allow debots to get data from main net smart contracts without deploying them main net
Some DeBots, need to get data from main net smart contracts, however I don't want to pay deployment fees each time I change something in the debot code. I think there's a need to allow running a debot that will interact with main net without deploying it to main net.
I have three ideas of how to implement this. A) Run the debot without deploying at all. Requires generating contract data and hacking the debot browser to run the debot without downloading it. B) Create a dapp proxy that will pass requests regarding this debot address to tonos se while redirecting all other requests to main.ton.dev. C) Downloading the required contracts from main net in advance and deploy them to tonos se.
ft
is currently not able to run debots. The reason is that, to run a debot, it would require to call OCaml from Rust (for example, to give access to wallet keys in the debot), and we haven't tested that with the current OCaml-Rust binding. Yet, the proposed feature would be a "must-have" feature when we start implementing debots.
I finally decided to give it a try. Here is what I have:
- Download
tonos-cli
from https://github.com/lefessan/tonos-cli, branchz-2021-08-23-debot-from-boc
- Set DEBOT_BOC_PRINT=1 in your environment, run the debot from TONOS SE , it should print the BOC it is using
- Set DEBOT_BOC=XXX where XXX is the printed BOC value, run the debot on another network, it should print "Using state from DEBOT_BOC" and run the debot with the saved state but on the new network...
Hey @lefessan, I was finally able to test the hack thoroughly, it has a problem. since you simply always return DEBOT_BOC whenever load_state is called, you are also preventing any getters on other smart contracts from being run locally. I think checking if the address requested is the address of the running debot would solve this problem. It's a good start though:)
Indeed. I have uploaded a new version (should just need to call cargo update
before cargo build
in tonos-cli
same branch). This time, the BOC of the debot is extracted from env variable DEBOT_XXX
for address 0:XXX
. DEBOT_BOC_PRINT=1
should display the name of that variable.
And another version:
- If
$DEBOT_SAVE_DIR
is defined, it will save the debot state in that directory (under nameDEBOT_XXX.boc
, where0:XXX
is the debot address) - If
$DEBOT_LOAD_DIR
is defined, it will load the debot state from that directory (from nameDEBOT_XXX.boc
)
Latest version of ft
automatically supports this behavior (since commit https://github.com/OCamlPro/freeton_wallet/pull/72/commits/b117b280ec4425f8555f6531ae17b5501fa7678b), using ft debot fetch --boc-from NETWORK ADDR
(where ADDR is the debot address on NETWORK). It will automatically download the BOC, save it in $DEBOT_LOAD_DIR and set the env var before calling tonos-cli
. However, you need to have the patched version of tonos-cli
in $HOME/.ft/bin/
.