Deploy
Last updated
Was this helpful?
Last updated
Was this helpful?
Find out how to deploy a contract to Everscale Blockchain with SDK
.
Core api is more flexible than , 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 deploy.
Deploy operation means that you upload contract code and initial data to the blockchain.
The address of the contract can be calculated before deploy and it depends on code and data.
To deploy a contract you need to sponsor its address, so that deploy fee will be paid out of these funds.
Below is the sequence of steps you need to complete:
Observe deploy parameters
Prepare a pair of keys
[optional] Prepare Initial contract data
Calculate future address of the contract
Transfer funds to the future address
Deploy
Let's take a look at every step.
Here is the structure, that is used to prepare initial contract state for deploy. It will define the future contract address.
workchain_is
- Target workchain where the contract will be deployed. By default is 0.
initial_data
- structure that contains public contract data fields with assigned values that need to be included into the initial state.
initial_pubkey
- owner pubkey. If not specified, pubkey is taken from Signer
. If you manage to specify contract owner directly in tvc
, then it will have priority above both initial_pubkey
and Signer
.
To deploy you will need a pair of keys to sign the deployment message. The keys are used during address generation, so the future contract address depends partially on the key as well.
If you want to make another person owner of the contract then specify their pubkey via DeploySet.initial_pubkey
.
In this guide we will use crypto.generate_random_sign_keys
function to generate a key pair.
Note: Please store these keys in a secure environment as you will need them to calculate the future address and deploy the contract. You might also need it to call contract functions in the future.
Placing data into storage always affects the future contract address.
This is useful for scenarios when you need to deploy several contracts with identical contract code (e.g. wallets) to different addresses.
If each contract is deployed with its own unique pair of keys, you do not need to use DeploySet.initial_data
as the addresses will be generated using the corresponding key pair each time.
To be used as initParams
variables must be declared as static
in the contract.
Constructor - is any contract function that will be called upon deploy. It will not influence contract address.
function_name
- function name that will be called upon deploy. Usually, it is called constructor
.
input
- object with function parameters.
Everscale blockchain requires every contract to have a positive token balance before deployment. The contract pays for the initial deployment message reducing account balance.
We will create deploy message and get future contract address from it.
You can either specify or not specify call_set here, it will not influence the address.
Note: Deployment requires the same pair of keys used for address calculation.
Note:
constructorParams
do not affect the address. OnlyinitParams
and the keys do. If you only plan to calculate address, you can omit this parameter.
Now that you know the address, you need to transfer the initial funds to it from your wallet or the Giver.
At this point, you're all set for deployment.
Note: Insufficient balance will result in a failed deployment.
Note: Everscale Blockchain does not guarantee a 100% external inbound messages success rate. There is a possibility that deployment will fail. To ensure success, please check for a completed transaction.
process_message
methodThis is an easy to implement pattern to deploy for server-side development and tests, but we do not recommend to use it in web and mobile applications because of network inconsistency and application crash probability. For more reliable approach - use the Pattern 2.
See the full example in sdk samples repository:
encode_message
-> send_message
-> wait_for_transaction
Any interaction with and within the Everscale blockchain is implemented via messages.
To deploy a contract, first you need to create a deploy message that will include all the initial data:
Now the message should be sent. send_message
method returns the the last block created in the shard before the message was sent.
send_events: false
flag specifies that we will not monitor message delivery events. Soon there will be a guide about message processing monitoring.
After the message was sent we need to wait for the transaction:
If wait_for_transaction
fails with 507 error - you can perform a retry. In all other cases retry may end up with double spends.
See the full example in sdk samples repository:
Often developers need to deploy one contract from another contract and try to pass tvc
file as a cell parameter for contract to use.
This is not a correct way.
To be able to deploy a contract from another contract you need to pass the contract's code as a cell parameter.
You can get it several ways:
See the "" guide to find out how to do it.
tvc
- As we discussed at the , contract compilation artifact, converted into base64.
In fact, keys are optional for deploy, but, if you want to be the contract owner then specify Signer object for that. .
If, however, all the contracts need to have the same contract code and have to be deployed with the same pair of keys but to different addresses, you may use placing data into storage through DeploySet.initial_data
to vary the addresses during .
It, together with its parameters, is specified in the structure:
header
- optional, can be specified for some complex use cases. .
Note: Evernode SE offers a pre-deployed giver. When in real networks, you need to use your wallet for this or deploy your own giver. We have separated guides of and of your own giver.
Method `process_message performs all the deploy steps sequentially in one method: create message, send it, wait for transaction and decode external outbound message generated by contract RETURN operator. The time limit can be set up in Client configuration. The default time setting is 40 seconds. You can learn more .
Check out how to run contract's methods in the next .
Check out how to run contract's methods in the next .
You can use SDK function of boc
module and retrieve the code's boc from tvc file.
You can download another account with the same code_hash
's boc
from graphql, using and retrieve the 'code' from the result boc
field.
Full sample:
Check out for this use case.