Smart Contract with Localchain possible?

Is it possible to deploy smartcontract on localchain for testing? Or is it only possible via testnet at the moment?

To make sure I have a working contract, I followed the steps for the crowdfunding example. Building works as expected via the IDE plugin. When I go to deploy any try to create the transaction, it just sits there with the loading icon forever (maybe action should have a timeout / fail immediately and disable button on click until the transaction completes). Using docker tag version of latest and updated since last week.

So my questions are:
Is it possible to use localchain for contract testing? If so, please add to documentation for the public. If I missed it, please let me know where I can find it.
Currently have the Klever node set to localhost. Is there a specific port needed?
Is the latest docker tag the correct tag to use for smart contract testing?

Thanks in advance!

1 Like

Hello @Joseph_RudeBoy welcome to the Klever Forum!

Yep, it’s possible. First of all, you can follow this steps to create a local testnet, and then, you can deploy and invoke your contracts by operator.

Let us know if you need more support

Thanks for the quick reply Duka!

I have the local testnet up and ready to go. I will give it a try by using the CLI for the operator and let you know how it goes!

Duka,

Not seeing and CLI operator commands options for deploy, invoke, upgrade contracts in the docs nor when going through the operator commands manually via docker image.

The operator page says it was last update in 2023 " Auto generated by spf13/cobra on 6-Mar-2023". Maybe this is missing from the public view?

Could you or someone from the team please share what the operator command would like to deploy/invoke a contract for a wasm & json file?

Hey @Joseph_RudeBoy , welcome to the Klever Forum!

It looks like you’re on the right track, but there’s a small issue with the Docker image you’re using (the one in the steps Duka sent). The kleverapp/klever-go:latest image is the MainNet one does not support smart contracts yet . You should use: kleverapp/klever-go:latest-testnet instead for smart contract testing.

For deploying and invoking smart contracts using the operator, here are the correct commands:


:hammer_and_wrench: Deploy a Smart Contract

KLEVER_NODE=${KLEVER_NODE} go run ./cmd/operator/ --key-file=${KEY_FILE} \
        sc create \
        --wasm=${WASM_FILE} \
        {--args u32:1 if any} \
        --readable --payable --upgradeable --await --result-only --sign

:high_voltage: Invoke a Smart Contract

KLEVER_NODE=${KLEVER_NODE} go run ./cmd/operator/ --key-file=${KEY_FILE} \
        sc invoke ${CONTRACT_ADDRESS} ${FUNCTION_NAME}  \
        {--args xxxx --args yyyy if any } \
        --await --result-only --sign

Let me know if you run into any issues! Also, if you’re interested, I may be able to provide an easier step to deploy a single node for testing—just let me know if you’d like that. :rocket:

4 Likes

Thanks for the update! I was able to get the nodes up and running locally and will try the commands soon!

Some things to note for those coming after me if following the docs so far:

  1. Docs use mainnet config. Look under testnet and should be the following or later → https://backup.testnet.klever.org/config.testnet.109.tar.gz
  2. Docker images now look under config/node. Might see error failed to find config file. Will have to update your volumes in your docker-compose.yml from ./config:/opt/… to ./config/node:/opt/…
  3. Might see error for min consensus nodes exceed min number of nodes. Update your you nodeSetupjson config for consensusGroupSize to number of nodes in local test net. I had 2 like the docs.

How do I prevent this error, I got it while building a Contract
error[E0554]: #![feature] may not be used on the stable release channel
→ /home/eldiablo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/klever-sc-derive-0.43.3/src/lib.rs:4:1
|
4 | #![feature(proc_macro_quote)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Checking clap_builder v4.5.1

For more information about this error, try rustc --explain E0554.
error: could not compile klever-sc-derive (lib) due to 1 previous error

Hello @Abbeyfx!

Every time you start a new project, make sure to run the following commands in your terminal, inside the project’s root folder:

rustup override set nightly-2024-06-12
rustup target add wasm32-unknown-unknown

These commands ensure you’re using the correct Rust toolchain and target for building smart contracts.

1 Like