Working with DevNet is similar to working with SE except you usually don't have any predeployed giver in DevNet. So you need to fund your contracts manually or deploy your own giver, which you will be able to use the same way as in SE. Deploying your own giver can be useful, if you need to deploy many contracts or need to frequently redeploy and test contract after subsequent modification.
In this guide we will show you how you can use your own Giver in the core SDK.
First of all, let's initialize giver's address, keys and ABI. All the data in this example are used from Evernode SE giver, substitute them by your Giver's data.
Next, implement a function to request tokens from the Giver:
// Requesting test tokens from the GiverasyncfunctiongetTokensFromGiver(client, account, amount) {// Execute method `sendTransaction` of the Evernode SE Giver v2 contract:constprocessingResult=awaitclient.processing.process_message({ send_events:false, message_encode_params: { address: giverAddress, abi: giverAbi, call_set: { function_name:'sendTransaction', input: { dest: account, value: amount, bounce:false } }, signer: giverSigner, }, });// Wait until all messages have been produced:consttransactionTree=awaitclient.net.query_transaction_tree({ in_msg:processingResult.transaction.in_msg, });// Make additional checks to ensure success:if (transactionTree.transactions.length!==2) { throw `Something went wrong during requesting funds from the Giver: there must be 2 transactions, but actual count is ${transactionTree.transactions.length}`;
}if (transactionTree.transactions[1].account_addr !== account) { throw "Something went wrong during requesting funds from the Giver: 2nd transaction's account address must be " + account;
}}
Now you can use your new function for funding your contracts before deployment:
asyncfunctionmain(client) {// Define contract ABI in the Application // See more info about ABI type here https://github.com/tonlabs/ever-sdk/blob/master/docs/mod_abi.md#abiconstabi= { type:'Contract', value:HelloWallet.abi }// Generate an ed25519 key pairconsthelloKeys=awaitclient.crypto.generate_random_sign_keys();// Prepare parameters for deploy message encoding // See more info about `encode_message` method parameters here https://github.com/tonlabs/ever-sdk/blob/master/docs/mod_abi.md#encode_message
constdeployOptions= { abi, deploy_set: { tvc:HelloWallet.tvc, initial_data: {} }, call_set: { function_name:'constructor', input: {} }, signer: { type:'Keys', keys: helloKeys } }// Encode deploy message// Get future `Hello` contract address from `encode_message` result// to sponsor it with tokens before deployconst { address } =awaitclient.abi.encode_message(deployOptions);console.log(`Future address of the contract will be: ${address}`);// Request contract deployment funds form the GiverawaitgetTokensFromGiver(client, address,1_000_000_000);console.log(`Tokens were transfered from giver to ${address}`);// Deploy `hello` contract// See more info about `process_message` here // https://github.com/tonlabs/ever-sdk/blob/master/docs/mod_processing.md#process_messageawaitclient.processing.process_message({ send_events:false, message_encode_params: deployOptions });console.log(`Hello contract was deployed at address: ${address}`);}