Skip to content

Instantly share code, notes, and snippets.

@mikekeke
Created May 24, 2023 11:22
Show Gist options
  • Save mikekeke/1efd882a9f7317c095073bed5f78e2f0 to your computer and use it in GitHub Desktop.
Save mikekeke/1efd882a9f7317c095073bed5f78e2f0 to your computer and use it in GitHub Desktop.
promise-then
async function deploy() {
contract.setContractHash("hash-2131266e1784f2f1bd9061f579f4a55ef04b40d1e11ad7dc12dd9597d3870f05");
provider.getActivePublicKey()
.then(pubKeyHex => {
console.log("PK hex: " + pubKeyHex);
const pubKey = CLPublicKey.fromHex(pubKeyHex);
const deploy = contract.callEntrypoint(
"counter_inc",
RuntimeArgs.fromMap({}),
pubKey,
"casper-test",
"160000000"
);
const deployJson = DeployUtil.deployToJson(deploy);
console.log(deploy);
return provider.sign(JSON.stringify(deployJson), pubKeyHex)
.then(sig => { return [sig, deploy, pubKey] });
})
.then(res => {
const [signature, deploy, pubKey] = res
if (signature.cancelled) {
throw new Error("Sign cancelled");
} else {
console.log("here-1");
const signedDeploy = DeployUtil.setSignature(
deploy,
signature.signature,
pubKey
);
console.log("here-2");
return signedDeploy;
}
})
.then(signedDeploy => {
console.log('Sign successful:')
console.log(signedDeploy);
sendDeploy(signedDeploy);
})
.then(deployResponse => {
console.log("Depl resp: " + deployResponse);
})
.catch(err => {
alert('Deploy error: ' + err);
})
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment