'Pass contract's code and data to another contract via CLI
Working on contract fabric, starting with the sample.
TvmCell stateInit = tvm.buildStateInit(templateCode, templateData);
code
and data
are TvmCell
s of a template contract and must be passed as parameters.
We can get those info from a template contract this way: (tvm.code(), tvm.getData());
or tonos-cli decode
. And then convert to TvmCell
like this
TvmBuilder cb;
cb.store(code);
TvmBuilder db;
db.store(data);
templateCode = cb.toCell();
teamplteData = db.toCell();
Woking with the TONOS SE command line tools, the workflow essentially looks like this:
tondev c r Contract GetCodeAndData | pcregrep -M -o1 'value0\": \"(.+?)\"' | base64 -d | xxd -p | tr -d '\n' > code.hex
tondev c r Contract GetCodeAndData | pcregrep -M -o1 'value1\": \"(.+?)\"' | base64 -d | xxd -p | tr -d '\n' > data.hex
tondev c r Fabric deployWithCodeAndData -i code:$(cat code.hex),data:$(cat data.hex)
and this looks like working as expected, a new contract address is returned. However, an attempt to run any method of the deployed contract results in
Running...
Error: Contract execution was terminated with error: Compute phase isn't succeeded, exit code: -5 (integer overflow).
Possible reason: Contract did not accept message (integer overflow).
The same runs on the original contract, which code is used for templating, work with no error. It looks like serialization or deserialization are not correct. What's wrong?
Solution 1:[1]
Get the tvm code and data via
code=$(tonos-cli decode stateinit --tvc contract.tvc | pcregrep -o1 'code": "(.+?)"')
data=$(tonos-cli decode stateinit --tvc document.tvc | pcregrep -o1 'data": "(.+?)"')
Call the function
function setCodeAndData(TvmCell c, TvmCell d)
:tondev c r Fabric.abi.json setTemplate -i c:$ddcode,d:$dddata
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | nivedano |