I am new to substrate. Am trying to deploy and instantiate a simple contract on a local node. Everything is via the command line (cargo), or node.js, no UI, no browser.
Am using paritytech's substrate-contracts-node because it already comes with contracts-pallet, and substrate-developer-hub's substrate-node-template does not seem to.
I create a simple project: cargo contract new flipper
.
Then, cargo +nightly contract build --release
.
Then, I make sure the node is running:
substrate-contracts-node --dev --detailed-log-output
(I don't think I even need any options).
Then, cargo contract upload --verbose --suri //Alice
.
Output on client-side:
$ cargo contract upload --verbose --suri //Alice
VERBOSE
Event Balances ➜ Withdraw
who: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
amount: 525756416
Event Balances ➜ Reserved
who: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
amount: 314475000000
Event Contracts ➜ CodeStored
code_hash: 0x4406fe2cdb0473a8925be201d3452ce15a0988406c7eb4fb48a6ca324bac2733
Event TransactionPayment ➜ TransactionFeePaid
who: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
actual_fee: 525756416
tip: 0
Event System ➜ ExtrinsicSuccess
dispatch_info: DispatchInfo { weight: 439457000, class: Normal, pays_fee: Yes }
Code hash 0x4406fe2cdb0473a8925be201d3452ce15a0988406c7eb4fb48a6ca324bac2733
I use the code hash for the instantiate command:
code_hash=0x4406fe2cdb0473a8925be201d3452ce15a0988406c7eb4fb48a6ca324bac2733;
cargo contract instantiate \
--verbose \
--constructor new \
--suri //Alice \
--code-hash $code_hash
Output client side:
ERROR: Module error: Contracts: OutOfGas
The executed contract exhausted its gas limit.
The output on the terminal running the node: (deploy):
2022-07-29 00:14:17 🙌 Starting consensus session on top of parent 0x2f9fcaae0e2c09157198db93ab7d30c0251d033203604f730a06f9bfd1a285df
2022-07-29 00:14:17 🎁 Prepared block for proposing at 11 (4 ms) [hash: 0x5e9b43d696429a702669b92b50ec21ff6e5f1b68d52c30bf8a4180d023a449be; parent_hash: 0x2f9f…85df; extrinsics (2): [0x238c…aa21, 0xc325…d77b]]
2022-07-29 00:14:17 Instant Seal success: CreatedBlock { hash: 0x5e9b43d696429a702669b92b50ec21ff6e5f1b68d52c30bf8a4180d023a449be, aux: ImportedAux { header_only: false, clear_justification_requests: false, needs_justification: false, bad_justification: false, is_new_best: true } }
2022-07-29 00:14:17 ✨ Imported #11 (0x5e9b…49be)
Node terminal ouput: (instantiate):
2022-07-29 00:16:04 Accepting new connection, 1/100
2022-07-29 00:16:04 🙌 Starting consensus session on top of parent 0x5e9b43d696429a702669b92b50ec21ff6e5f1b68d52c30bf8a4180d023a449be
2022-07-29 00:16:04 🎁 Prepared block for proposing at 12 (0 ms) [hash: 0x24704f81396e053fc4861656dee410a52cad8203900ae99ef89c03795f9f5178; parent_hash: 0x5e9b…49be; extrinsics (2): [0x64cf…1ada, 0xf68f…52bd]]
2022-07-29 00:16:04 Instant Seal success: CreatedBlock { hash: 0x24704f81396e053fc4861656dee410a52cad8203900ae99ef89c03795f9f5178, aux: ImportedAux { header_only: false, clear_justification_requests: false, needs_justification: false, bad_justification: false, is_new_best: true } }
2022-07-29 00:16:04 ✨ Imported #12 (0x2470…5178)
So now what? I think my use of cargo contract
is out as far as "gas" is concerned.
Willing to write up a node.js client (@polkadot/api
), but not sure how to proceed. Who needs the "gas"... the contract? If so, how do I get a reference/id/address to it?
Should that have happened during deployment, during instantiation? Are the starting default values for //Alice
too little?
I am not clear as to the exact problem, thus how to solve it.
UPDATE:
Thank you to Alexander Theißen, I think I got past the original "gas limit" problem.
I am still not quite sure if I have all of the correct parameters for the cargo contract instantiate
command.
Here is what I have:
code_hash=0x4406fe2cdb0473a8925be201d3452ce15a0988406c7eb4fb48a6ca324bac2733
cargo contract instantiate \
--verbose \
--storage-deposit-limit 50000000000 \
--gas 50000000000 \
--constructor new \
--args false \
--suri //Alice \
--code-hash $code_hash
The error is:
ERROR: Rpc error: JSON-RPC call failed: RPC Call failed: code: 1002, message: Verification Error: Runtime error: Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction, data: Some(RawValue("RuntimeApi(\"Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction\")"))
Caused by:
0: JSON-RPC call failed: RPC Call failed: code: 1002, message: Verification Error: Runtime error: Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction, data: Some(RawValue("RuntimeApi(\"Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction\")"))
1: RPC Call failed: code: 1002, message: Verification Error: Runtime error: Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction, data: Some(RawValue("RuntimeApi(\"Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction\")"))
However, if I use a UI: https://paritytech.github.io/contracts-ui, I can connect to the local substrate-contracts-node
and even just use the uploaded contract by supplying the UI with code_hash. From there I can successfully make calls to the contract.
So I assume the issue is related to something I am doing wrong with the cargo contract instantiate
parameters.