deploy method
Deploy a smart contract to blockchain
This is a single clause transaction. paramsTypes
Constructor params types, params
Constructor params, value
send VET in Wei with constructor call
Implementation
Future<Map> deploy(Wallet wallet, Contract contract, List<String> paramsTypes,
List params, BigInt value) async {
//build transaction body
Uint8List dataBytes;
if (paramsTypes.isEmpty) {
dataBytes = contract.getBytecode();
} else {
dataBytes = Uint8List.fromList(
contract.getBytecode() + buildParams(paramsTypes, params));
}
var data = "0x" + bytesToHex(dataBytes);
var b = await getBlock();
var txBody = buildTransaction(
[dev.Clause(null, value.toString(), data)],
await getChainTag(),
calcBlockRef(b["id"]),
calcNonce(),
gas: 0, // We will estimate the gas later
);
var eResponses = await emulateTx(
wallet.adressString, json.decode(txBody.toJsonString()));
if (anyEmulateFailed(eResponses)) {
throw Exception("Tx will revert: $eResponses");
}
// Get gas estimation from remote
var vmGas = readVmGases(eResponses).sum;
var safeGas = suggestGasForTx(vmGas, json.decode(txBody.toJsonString()));
// Fill out the gas for user.
txBody.gas.big = BigInt.from(safeGas);
Uint8List h = blake2b256([txBody.encode()]);
Uint8List sig = sign(h, wallet.priv).serialize();
txBody.signature = sig;
String raw = '0x' + bytesToHex(txBody.encode());
//var encodedRaw = calcTxSignedEncoded(wallet, txBody);
//print(encodedRaw);
return postTransaction(raw);
}