Run on-chain
Learn how to run methods of a contract on-chain
Core api is more flexible than AppKit and you can perform a lot of complex logic using it. But you will need to write more code with it as well :)
You need to define the contract in your node.js application before running its methods.
Full sample: https://github.com/everx-labs/sdk-samples/tree/master/core-examples/node-js/hello-wallet
About run
Run operation consists of few steps:
Creating a message;
Sending a message;
Receiving the message completion transaction;
Receiving external messages created by
return
function;Decoding the messages bodies according to the ABI.
Run on-chain
Pattern 1. Run in 1 step: process_message
method
process_message
methodThe process_message method runs ABI-compatible contract method on-chain and returns the result transaction along with the external messages bocs, and decoded external messages bodies.
process_message
performs all the run operation steps inside.
Note: This is an easy to implement pattern to run, but we do not recommend to use it because of network inconsistency and application crash probability. For more reliable approach - use the Pattern 2.
For example, a contract has such method:
Client method call:
See the full sample in the repository with sdk samples:
https://github.com/everx-labs/sdk-samples/tree/master/core-examples/node-js/hello-wallet
Pattern 2. Run in 3 steps: encode_message
-> send_message
-> wait_for_transaction
encode_message
-> send_message
-> wait_for_transaction
To run a contract method, first you need to create a run message:
Now the message should be sent. sendMessage
method returns the the last block created in the shard before the message was sent.
After the message was sent we need to wait for the transaction starting from the last shard block:
Calculate account fees
Retrieve result.fees
object of process_message
or wait_for_transaction
. You need result.fees.account_fees
for total account fees value.
Fees object detailed explanation
Here is the structure of fees object.
storage_fee
: bigint – Fee for account storagegas_fee
: bigint – Fee for processingin_msg_fwd_fee
: bigint – Deprecated. Left for backward compatibility.ext_in_msg_fee
: bigint – Fee for inbound external message import.total_fwd_fees
: bigint – Total fees the account pays for message forwardingaccount_fees
: _bigint_** – Total account fees for the transaction execution. Compounds of storage_fee + gas_fee + ext_in_msg_fee + total_fwd_fees**
Deprecated fields. Left for backward compatibility.
out_msgs_fwd_fee
: bigint – Deprecated. Left for backward compatibility.total_account_fees
: bigint – Deprecated. Left for backward compatibility. This is the field that is named astotal_fees
in GraphQL API Transaction type.total_account_fees
name is misleading, because it does not mean account fees, instead it means validators total fees received for the transaction execution. It does not include some forward fees that account actually pays now, but validators will receive later during value delivery to another account (not even in the receiving transaction but along the way of a chain of transactions processing). Because of all of this, this field is not interesting for those who want to understand the real account fees, this is why it is deprecated and left for backward compatibility.total_output
: bigint – Deprecated. Left for backward compatibility.
See the full example in sdk samples repository: https://github.com/everx-labs/sdk-samples/blob/master/core-examples/node-js/hello-wallet/index_pattern2.js
Check out AppKit documentation for this use case.
Last updated