Upload Program
A program compiled to Wasm can be uploaded to the Vara network. During uploading, it is initialized in the network to be able to send and receive messages with other actors in the network (programs and users).
Use api.program.upload method to create upload_program extrinsic
const code = fs.readFileSync('path/to/program.wasm');
const program = {
code,
gasLimit: 1000000,
value: 1000,
initPayload: somePayload,
};
try {
const { programId, codeId, salt, extrinsic } = api.program.upload(
program,
meta,
);
} catch (error) {
console.error(`${error.name}: ${error.message}`);
}
try {
await extrinsic.signAndSend(keyring, (event) => {
console.log(event.toHuman());
});
} catch (error) {
console.error(`${error.name}: ${error.message}`);
}Gas Calculation for Init
To calculate the gas required for processing an init message, use the following method:
api.program.calculateGas.initUpload()
For a deeper dive into the gas mechanics, see the Calculate Gas documentation.