Using Beam contracts with CLI Wallet

Getting Started

You can download Beam compatible binaries for your platform at beam.mw​
If you would like to build Beam yourself from source code please refer to the Building Instructions Guide​
We strongly recommend that you get the node and the CLI wallet in addition to the Desktop wallet even if you only intend to use Beam. The reason for that is that many interesting contracts you might want to run will take time to provide graphical applications. Having your own node and running CLI wallet will allow you to use the newest and coolest features. It is not complicated, as we will see in a minute.

Getting the Shaders

​
Beam Smart Contracts are implemented with special programs called Beam Shaders. Shaders are small (or not so small) programs that can be written in several different programming languages but are eventually compiled to .wasm files (since Beam Virtual Machine runs on something called WebAssembly)
To get started you do not need to write or build Shaders yourself. Instead you can download the latest samples and examples from our repository here:
As you can see, there are several folders there called 'faucet', 'dao-core' ' and maybe others. In each of those folders are two files usually called 'contract.wasm' and 'app.wasm'.
The reason for that is that each application comes in two parts. One part is the contract that is deployed to the blockchain (contract.wasm) and the other one is used by the wallet to interact with the contract (app.wasm)
We suggest to create a folder called 'shaders' under the 'beam' folder and put the subfolder with specific apps like 'faucet' and such there.
Now let's see how we can run some apps!

Faucet contract

All commands for Faucet contract

To see all the commands for a contact, use the following command
1
./beam-wallet shader --shader_app_file shaders/faucet/app.wasm -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file shaders/faucet/app.wasm -n 127.0.0.1:8501
2
​
3
I 2021-10-19.16:16:18.853 Beam Wallet 6.1.12023 (mainnet)
4
I 2021-10-19.16:16:18.854 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
5
I 2021-10-19.16:16:18.854 starting a wallet...
6
I 2021-10-19.16:16:19.093 wallet successfully opened...
7
Executing shader...
8
Shader output: {"roles": {"manager":
9
{"create": {"backlogPeriod": "Height","withdrawLimit": "Amount"},
10
"destroy": {"cid": "ContractID"},"view": {},"view_params": {"cid": "ContractID"},
11
"view_funds": {"cid": "ContractID"},"view_accounts": {"cid": "ContractID"},
12
"view_account": {"cid": "ContractID","pubKey": "PubKey"}},
13
"my_account": {"view": {"cid": "ContractID"},
14
"deposit": {"cid": "ContractID","amount": "Amount","aid": "AssetID"},
15
"withdraw": {"cid": "ContractID","amount": "Amount","aid": "AssetID"}}}}
Copied!

View contract

Make sure you have downloaded the latest version of the 'faucet' contract folder and put it under the 'shaders' folder as instructed. You need app.wasm to use the faucet and contract.wasm to deploy your own contract.
In this section we will use Beam Faucet contract to get contract cid on the Beam chain.
    Open the Command Prompt (on Windows), Shell (on Linux) or Terminal (on MacOS) and change directory to the location of your Beam CLI wallet.
    Run the following command (assmuing app.wasm is located in shaders/faucet/app.wasm)
1
./beam-wallet shader --shader_app_file shaders/faucet/app.wasm -n 127.0.0.1:8501 --shader_args="role=manager,action=view"
Copied!
1
./beam-wallet shader --shader_app_file shaders/faucet/app.wasm -n 127.0.0.1:8501 --shader_args="role=manager,action=view"
2
​
3
I 2021-10-19.16:16:18.853 Beam Wallet 6.1.12023 (mainnet)
4
I 2021-10-19.16:16:18.854 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
5
I 2021-10-19.16:16:18.854 starting a wallet...
6
I 2021-10-19.16:16:19.093 wallet successfully opened...
7
Executing shader...
8
I 2021-10-19.16:34:07.670 Tip has not been changed
9
I 2021-10-19.16:34:07.674 Current state is 1463705-3c732eee8cdb116f
10
Shader output: {"contracts":
11
[{"cid": "3fdd4171972875e0ac8f0131b3da047e8323cc9c2c8d53327be427c455d2a716",
12
"Height": 1280003}]}
13
​
Copied!
We assume that your wallet is initialized and your node is running on local machine at port 8501 and that faucet app.wasm is located in the shaders/faucet folder. If your parameters are different please adjust them accordingly.
The result of this command will be the list of contract ids of shaders of type 'faucet' that are currently deployed on the network. The reason that there can be more than one such shader is because the same Application Shader (app.wasm) can interact with several different Contract Shaders (contract.wasm) of the same type.

Withdraw beams from contract

To withdraw the 0.05 beam from the Faucet contract use this command
1
./beam-wallet shader --shader_app_file shaders\faucet\app.wasm --shader_args="role=my_account,action=withdraw,cid=3fdd4171972875e0ac8f0131b3da047e8323cc9c2c8d53327be427c455d2a716,amount=6100000" -n 127.0.0.1:8501
Copied!
You can replace the cid parameter with a different contract id that you have received as a result of step view contract.
When getting coins from Faucet contract, fee is taken from it, so you will receive 0.061 - 0.011(Fee) = 0.05 Beam
This operation can result in several different outcomes:
    Each faucet has a limit on how many Beam coins you can withdraw each time within a give period. Both of these are 'constructor parameters' of the shader that are specified when it is If you are under that limit for that period you should receive the Beams that you have requested.
    If you are over the limit you will either receive nothing or a Magical Error 17, depending on the contract implementation.
    You will also receive the Magical Error 17 if something else is wrong with the contract.
But how do I know what are the contract parameters?

Contract parameters

To see the contract parameters use this command
1
./beam-wallet shader --shader_app_file shaders\faucet\app.wasm --shader_args="role=manager,action=view_params,cid=3fdd4171972875e0ac8f0131b3da047e8323cc9c2c8d53327be427c455d2a716" -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file shaders\faucet\app.wasm --shader_args="role=manager,action=view_params,cid=3fdd4171972875e0ac8f0131b3da047e8323cc9c2c8d53327be427c455d2a716" -n 127.0.0.1:8501
2
I 2021-10-19.17:06:35.384 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-19.17:06:35.385 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-19.17:06:35.386 starting a wallet...
5
I 2021-10-19.17:06:35.744 wallet successfully opened...
6
Executing shader...
7
Shader output: {"params": {"backlogPeriod": 1440,"withdrawLimit": 6100000}}
Copied!
As a result you will get something like this:
Shader output: "": {"params": {"backlogPeriod": 1440,"withdrawLimit": 6100000}}
This means that from this faucet, you can extract up to 0.061 Beam every 1440 blocks

Deposit beams to contract

To send the 0.05 beam to the Faucet contract use this command
1
./beam-wallet shader --shader_app_file shaders\faucet\app.wasm --shader_args="role=my_account,action=deposit,cid=3fdd4171972875e0ac8f0131b3da047e8323cc9c2c8d53327be427c455d2a716,amount=5000000" -n 127.0.0.1:8501
Copied!
You can replace the cid parameter with a different contract id that you have received as a result of step view contract.

Create your Faucet

Since Faucet is not an 'ownable' contract (it will be explained later, but basically it means that it does not have an implicit owner) you can not create another faucet contract with the same parameters Therefore you should just invent a couple of parameters of your own, which should not be difficult enough in this case.
Since you are deploying a new contract on Beam blockchain, you need to make sure you have the appropriate contract.wasm file for it. We will assume that you have it in the same folder as the app.wasm
Now that these two things are out of the way, let's run the following command:
1
./beam-wallet shader --shader_app_file shaders/faucet/app.wasm -n 127.0.0.1:8501 --shader_args="role=manager,action=create,backlogPeriod=13,withdrawLimit=520000000" --shader_contract_file shaders/faucet/contract.wasm
Copied!
Assuming no one before you deployed a faucet that allowed to get up to 5.2 Beams every 13 blocks, you deployment will be successful and you will get a new contract id in returned value.
No all that is left to do is to deposit some funds into your faucet and let people of the world know it exists (just give them the id)

BeamX DAO contract

Our goal is to make the Beam ecosystem as decentralized as possible, giving the stakeholders full control over the protocol governance.
Stakeholder can vote on all aspects of the ecosystem through ownership of the BeamX governance token.
Voters are incentivized to vote; their choices, identity and holdings are completely private
100M total supply with 4-year emission schedule. Can be farmed by staking Beam.

All comands for BeamX DAO contract

To see all the commands for a contact, use the following command
1
./beam-wallet shader --shader_app_file Shaders\dao-core\app.wasm -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file Shaders\dao-core\app.wasm -n 127.0.0.1:8501
2
I 2021-10-21.12:12:37.014 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.12:12:37.015 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.12:12:37.015 starting a wallet...
5
I 2021-10-21.12:12:37.229 wallet successfully opened...
6
Executing shader...
7
Shader output: {"roles": {"manager": {"view": {},"explicit_upgrade": {"cid": "ContractID"},
8
"view_params": {"cid": "ContractID"},"my_xid": {},
9
"my_admin_key": {},"prealloc_totals": {"cid": "ContractID"},
10
"prealloc_view": {"cid": "ContractID"},
11
"prealloc_withdraw": {"cid": "ContractID","amount": "Amount"},
12
"farm_view": {"cid": "ContractID"},
13
"farm_get_yield": {"cid": "ContractID","amount": "Amount","hPeriod": "Height"},
14
"farm_totals": {"cid": "ContractID"},
15
"farm_update": {"cid": "ContractID","amountBeamX": "Amount","amountBeam": "Amount","bLockOrUnlock": "uint32_t"}}}}
Copied!

View contract

Make sure you have downloaded the latest version of the 'dao-core' contract folder and put it under the 'shaders' folder as instructed. You need app.wasm to use the faucet and contract.wasm to deploy your own contract.
    Open the Command Prompt (on Windows), Shell (on Linux) or Terminal (on MacOS) and change directory to the location of your Beam CLI wallet.
    Run the following command (assmuing app.wasm is located in shaders/dao-core/app.wasm)
1
./beam-wallet shader --shader_app_file shaders/dao-core/app.wasm -n 127.0.0.1:8501 --shader_args="role=manager,action=view"
Copied!
1
./beam-wallet shader --shader_app_file shaders/dao-core/app.wasm -n 127.0.0.1:8501 --shader_args="role=manager,action=view"
2
I 2021-10-19.16:16:18.853 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-19.16:16:18.854 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-19.16:16:18.854 starting a wallet...
5
I 2021-10-19.16:16:19.093 wallet successfully opened...
6
Executing shader...
7
Shader output: {"versions": [{"Number": 0,"Height": 1464845,"cid": "3db292122e26df7b216ae89ae7504c9068b87273f149059915c6f4abbf72ee2d"}],
8
"contracts": [{"cid": "3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b","Height": 1464852,"min_upgrade_delay": 10000,
9
"min_approvers": 1,
10
"admins": [{"id": 0,"pk": "cbf7c381febb71d61457cc51d52f5b1ce53b45eee92734d2bdb293d82a25355000"}],
11
"current_version": 0}]}
Copied!
The result of this command will be the display of the contract that is registered in Beam blockchain.
This is the cid of the contract:
"contracts": [{"cid": "3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b"

Staking Beam

In order to send Beam to a contract and receive a BeamX reward, use the following command
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeam=1600000000,bLockOrUnlock=1 -n 127.0.0.1:8501
Copied!
The minimum amount to receive a reward is 16 Beam, from this amount you begin to receive a BeamX reward
This command, we sent 16 Beam to the contract
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeam=1600000000,bLockOrUnlock=1 -n 127.0.0.1:8501
2
I 2021-10-21.19:42:42.354 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.19:42:42.354 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.19:42:42.355 starting a wallet...
5
I 2021-10-21.19:42:42.607 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.19:42:42.667 Tip has not been changed
8
I 2021-10-21.19:42:42.670 Current state is 1466765-f25f1929fb7fff03
9
Shader output: {}
10
Creating new contract invocation tx on behalf of the shader
11
Comment: Lock/Unlock and get farmed beamX tokens Send 16 BEAM
12
Total fee: 1100000 GROTH
13
I 2021-10-21.19:42:51.192 [784c1ac2d03d4832aa5136d2f3762eb2][1] Get proof for kernel: d973ed7374e571f8
14
I 2021-10-21.19:42:51.206 [784c1ac2d03d4832aa5136d2f3762eb2] Transaction completed
Copied!
How can we see when BeamX have accumulated ?

Farm view

To see how many BeamX are farmed, use the following command
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_view,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_view,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
2
I 2021-10-21.19:48:56.753 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.19:48:56.754 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.19:48:56.755 starting a wallet...
5
I 2021-10-21.19:48:57.005 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.19:48:57.069 Sync up to 1466769-c8c91bf474915cfe
8
I 2021-10-21.19:48:57.069 Synchronizing with node: 0% (0/1)
9
I 2021-10-21.19:48:57.081 Synchronizing with node: 100% (1/1)
10
I 2021-10-21.19:48:57.081 Current state is 1466769-c8c91bf474915cfe
11
Shader output: {"farming": {"duation": 268,"emission": 203957381876,"h": 1466769,"h0": 252840},
12
"user": {"beams_locked": 1600000000,"beamX_old": 569592,"beamX_recent": 65919,"beamX": 635511}}
Copied!
We can see the parameters for user ,where:
    beams_locked - is your number of Beams in the stacking
    beamX_old - is number of BeamX that have already been credited to you
    beamX_recent - is the forecast of your reward
    beamX - are BeamX that you can withdraw from the stacking

Withdraw BeamX

You can find out the number of available BeamX using this command(farm_view), and to withdraw them, use the following command
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeamX=635511 -n 127.0.0.1:8501
Copied!
​
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeamX=635511 -n 127.0.0.1:8501
2
I 2021-10-21.21:34:07.371 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.21:34:07.371 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.21:34:07.371 starting a wallet...
5
I 2021-10-21.21:34:07.620 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.21:34:07.682 Tip has not been changed
8
I 2021-10-21.21:34:07.685 Current state is 1466870-f3aa6e59a16e3c3c
9
Shader output: {}
10
Creating new contract invocation tx on behalf of the shader
11
Comment: Lock/Unlock and get farmed beamX tokens Recv 635511 ASSET-7-GROTH
12
Total fee: 1100000 GROTH
13
I 2021-10-21.21:35:06.460 [1a2ca260c4a74a7ca4261c812ba68ed2][1] Get proof for kernel: 7c87ecc149b7c77a
14
I 2021-10-21.21:35:06.475 [1a2ca260c4a74a7ca4261c812ba68ed2] Transaction completed
Copied!

Staking and Withdraw in 1 transaction

If you want to add Beams in your stacking and get BeamX, then you can do it in 1 transaction, use the following command:
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeamX=635511,amountBeam=10000000,bLockOrUnlock=1 -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeamX=635511,amountBeam=10000000,bLockOrUnlock=1 -n 127.0.0.1:8501
2
I 2021-10-21.21:39:17.636 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.21:39:17.637 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.21:39:17.637 starting a wallet...
5
I 2021-10-21.21:39:17.886 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.21:39:19.075 Sync up to 1466878-4ee8a74a8f1e1175
8
I 2021-10-21.21:39:19.075 Synchronizing with node: 0% (0/1)
9
I 2021-10-21.21:39:19.076 Synchronizing with node: 100% (1/1)
10
I 2021-10-21.21:39:19.077 Current state is 1466878-4ee8a74a8f1e1175
11
Shader output: {}
12
Creating new contract invocation tx on behalf of the shader
13
Comment: Lock/Unlock and get farmed beamX tokens Send 10000000 GROTH
14
Recv 635511 ASSET-7-GROTH
15
Total fee: 1100000 GROTH
Copied!
​
Also you can withdraw Beam and BeamX in 1 transaction , just to specify "bLockOrUnlock= "in shader_args where : 0 - withdraw Beam , 1 - send Beam
--shader_args role=manager,action=farm_update,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b,amountBeamX=635511,amountBeam=10000000,bLockOrUnlock=1

Contract parameters

To see the contract parameters use this command
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=view_params,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=view_params,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
2
I 2021-10-21.22:15:32.925 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.22:15:32.926 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.22:15:32.927 starting a wallet...
5
I 2021-10-21.22:15:33.176 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.22:15:33.238 Tip has not been changed
8
I 2021-10-21.22:15:33.240 Current state is 1466907-15c917e6c0cdaa1b
9
Shader output: {"params": {"aid": 7,"locked_beamX": 9999983410129195,"locked_beams": 1126598099627933}}
Copied!
As a result you will get something like this:
Shader output: "{"params": {"aid": 7,"locked_beamX": 9999983410129195,"locked_beams": 1126598099627933}}
Where :
aid = 7 is asset number
locked_beamX = BeamX that are still available
locked_beams = Total amount in the contract
We can also see more details, for example, the number of users who were staking Beams, use this command
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=view_farm,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
Copied!
1
./beam-wallet shader --shader_app_file Shaders/dao-core-masternet/app.wasm --shader_args role=manager,action=view_farm,cid=3f3d32e38cb27ac7b5b67343f81cf2f8bc53217eb995cc6c5d78ddc5e7b0642b -n 127.0.0.1:8501
2
I 2021-10-21.22:55:47.434 Beam Wallet 6.1.12023 (mainnet)
3
I 2021-10-21.22:55:47.435 Rules signature: 0-ed91a717313c6eb0, 321321-6d622e615cfd29d0, 777777-1ce8f721bf0c9fa7, 1280000-3eaab6ab65b65f94
4
I 2021-10-21.22:55:47.435 starting a wallet...
5
I 2021-10-21.22:55:48.634 wallet successfully opened...
6
Executing shader...
7
I 2021-10-21.22:55:48.695 Tip has not been changed
8
I 2021-10-21.22:55:48.697 Current state is 1466935-6d5753dbb8b989d0
9
Shader output: {"duation": 435,
10
"total": 100000000000000,
11
"total_users": 1056,
12
"avail": 331050228045,
13
"received": 12621458260,
14
"beam_locked": 1152179812748426}
Copied!
We can see here number of staking Beams(total_users), the number of BeamX that are available but not distributed to users(avail), the number of BeamX that were distributed (received), and the number of Beams that were staking (beam_locked)
Last modified 1d ago