Deploy
Find out how to deploy a contract to Everscale Blockchain with SDK
About 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.
Deploy steps
Below is the sequence of steps you need to complete to deploy a contract:
Initialize Account object with Contract data and a pair of keys that will be used later to interact with it.
Calculate future address of the contract - In this case - just for information.
Deploy
Let's take a look at every step.
Initialize Account object
To initialize an account, we need:
Contract object, that we import from
HelloContract.js
. We prepared this file when adding contract to our app.Account options, that are passed as the following structure:
We will generate a pair of keys with generate_random_sign_keys
function and use them as Signer in this sample.
We do not have any initData
here, we do not know the address yet, and we will use the default client, so the only field we define in the second parameter AccountOptions
is Signer.
Or you can use a predefined set of keys.
Calculate the future address of the contract
Everscale blockchain requires every contract to have a positive token balance before deployment. The contract pays for the initial deployment message reducing account balance. To sponsor account before deploy we need to calculate its address.
Under the hood this calculation is performed on tvc, initData
and pubkey
.
Define deploy parameters
To deploy a contract we need to pass AccountDeployOptions
structure into deploy
method:
Specify Giver
By default Account.getDefaultGiver()
is Evernode SE giver. It is integrated into Account module. We will use it. But you can always re-define it with method Account.giver(newGiver: AccountGiver)
with the following signature:
More details about implementing your custom giver with sample code here.
Deploy
Because our contract has a constructor function as init function without parameters, we can omit the other 2 deploy parameters:
Sample source code
https://github.com/tonlabs/sdk-samples/blob/master/demo/hello-wallet/index.js
Check out core api documentation for more information.
Last updated