Calling Commands with Substitutions

Displaying Wallet Information

The sub-command ft output can be used to display wallet information, and save it into files.

For example, to display the address associated with a wallet, you may use:

$ ft output --addr user0
0:108f6113fb0cad8c98b70e8ea3cfd12b52710ec20441d05ceb78cacb4f5566b7

You may save the output into a file:

$ ft output --addr user0 -o user0.addr

You may output the keyfile associated with an account:

$ ft output --keyfile user0 -o user0.keyfile
$ cat user0.keyfile
{
"public": "fd9ee2babfa35b65917f732316dbb3d31935ccacd2a0aa92e043f8c762e0da28",
"secret": "7883b5b2962f1a2d4891f52a16f125b855b6be61f84b162a4476a2f240c9e2c9"
}

And finally, you may just load a file and display it after performing some substitutions (see the last section here for a documentation of these substitutions):

$ cat keyfile.in
{
"public-key": "%{account:pubkey:%{env:FTUSER}}",
"private-key": "%{account:seckey:%{env:FTUSER}}"
}
$ FTUSER=user0 ft output --file keyfile.in
{
"public-key": "fd9ee2babfa35b65917f732316dbb3d31935ccacd2a0aa92e043f8c762e0da28",
"private-key": "7883b5b2962f1a2d4891f52a16f125b855b6be61f84b162a4476a2f240c9e2c9"
}

Calling Commands with substitutions

The sub-command ft client can be used to call external commands while performing substitutions on their arguments.

By default, ft client will call tonos-cli, passing its arguments:

$ ft client -- genphrase
Calling /home/lefessan/.ft/bin/tonos-cli --config \
   /home/lefessan/.ft/sandbox1/tonos-cli.config genphrase
Config: /home/lefessan/.ft/sandbox1/tonos-cli.config
Succeeded.
Seed phrase: "fancy current bean dice pet gasp you swift \
  balance unaware law fun"

Note that we must use -- before providing the arguments to the external commands, to prevent ft from interpreting them.

We can also call another command, using --exec to prevent ft from calling tonos-cli:

$ ft client --exec -- echo '%{account:address:user0}'
Calling echo 0:108f6113fb0cad8c98b70e8ea3cfd12b52710ec20441d05ceb78cacb4f5566b7
0:108f6113fb0cad8c98b70e8ea3cfd12b52710ec20441d05ceb78cacb4f5566b7

This feature can be use to script many commands, for example:

$ ft client -- genaddr  '%{contract:tvc:SetcodeMultisigWallet2}' \
  '%{contract:abi:SetcodeMultisigWallet2}' --genkey toto.surf

This command will generate a new key-pair, saved it into file toto.surf, which providing the command with the TVC and ABI files for the contract SetcodeMultisigWallet2 (the one used by the Surf web wallet).

Existing Substitutions

Substitutions are written as %{SUBST}, and can be recursive (substitutions are allowed within SUBST itself). If the substitution is unknown (bad syntax) or cannot be resolved, an error is thrown.

Here is a list of allowed expressions within SUBST:

  • env:VARIABLE : Replaced by environemnt (shell) variable VARIABLE
  • addr:zero : For 0:0000000000000000000000000000000000000000000000000000000000000000

On wallet accounts, for a known account ACCOUNT:

  • account:address:ACCOUNT : replaced by the raw address of the account
  • account:wc:ACCOUNT : replaced by the workchain ID of the account
  • account:pubkey:ACCOUNT : replaced by the pubkey of the account, without 0x
  • account:seckey:ACCOUNT : replaced by the secret of the account
  • account:passphrase:ACCOUNT : replaced by the passphrase of the account
  • account:keyfile:ACCOUNT : Generates a JSON keyfile in $HOME/.ft/tmp/, and replaced by the file name
  • account:contract:ACCOUNT : replaced by the name of recorded contract of the account if known
  • account:contract:tvc:ACCOUNT : replaced by the TVC file name for the contract of the account
  • account:contract:abi:ACCOUNT : replaced by the ABI file name of the contract of the account
  • account:payload:ACCOUNT:METH:PARAMS : replaced by the base64 encoding of the message payload, corresponding to calling METH with JSON arguments PARAMS

On contracts:

  • contract:tvc:CONTRACT :
  • contract:abi:CONTRACT :
  • contract:payload:CONTRACT:METH:PARAMS : Output payload base64

Misc:

  • node:url : Current node URL

  • ton:NUMBER : Convert NUMBER of tons to nanotons

  • file:FILENAME : Read content of filename

  • now : current Unix date

  • now[:CORRECTION]* : Current Unix date with corrections, given by:

    • plus:NUM:PERDIODS : add a delay
    • minus:NUM:PERIODS : subtract a delay

    where PERIODS is one of years, days, hours, mins or secs.

    Example: now:plus:3:days:plus:4:hours

Encoders, working on the rest of the substitution:

  • string:SUBST Take remaining SUBST without substituting, just as a string
  • read:SUBST : Do SUBST, then read it as a filename
  • hex:SUBST : Do SUBST, then convert to hexa
  • of-hex:SUBST : Do SUBST, then convert from hexa
  • base64:SUBST : Do SUBST, then convert to base64
  • of-base64:SUBST : Do SUBST, then convert from base64
  • get-code:SUBST : Do SUBST, interprete it as a TVC filename, whose code should be extracted using tvm_linker decode and passed in base64