|
<html> |
|
<head> |
|
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs/dist-web/conseiljs.min.js"></script> |
|
<script> |
|
const tezosNode = '<tezos-node-url>'; |
|
const conseilServer = { |
|
url: '<conseil-indexer-url>', |
|
apiKey: '<API key from nautilus.cloud>', |
|
network: '<...>' |
|
} |
|
const networkBlockTime = 30 + 1; |
|
|
|
let keyStore = {}; |
|
const alphanetFaucetAccount = { |
|
"mnemonic": [ "promote", "grape", "sea", "glide", "still", "suggest", "vehicle", "front", "bulb", "wolf", "cart", "cart", "surround", "creek", "cycle" ], |
|
"secret": "b43d272885698df92e01a9adac18e697e9db42d0", |
|
"amount": "24283188994", |
|
"pkh": "tz1RArF4HTSMHpKywvvU1qtHRg89eWQN1CLL", |
|
"password": "LieZc5k2PT", |
|
"email": "[email protected]" |
|
}; |
|
const secretKey = 'edskS1hYczoFBSmyXZrLJEViq5ksFs1N2L7QKdTF1q3ZJiXvBwmsVtfeBdCXytM1Tzo645JKYjt6iyhqDwUyFMzZTwsq8Y9NHq'; |
|
|
|
function clearRPCOperationGroupHash(hash) { |
|
return hash.replace(/\"/g, '').replace(/\n/, ''); |
|
} |
|
|
|
async function initAccount() { |
|
//keyStore = await conseiljs.TezosWalletUtil.unlockFundraiserIdentity(alphanetFaucetAccount.mnemonic.join(' '), alphanetFaucetAccount.email, alphanetFaucetAccount.password, alphanetFaucetAccount.pkh); |
|
keyStore = await conseiljs.TezosWalletUtil.restoreIdentityWithSecretKey(secretKey); |
|
} |
|
|
|
async function invokeContract() { |
|
const augend = document.getElementById('augend').value; |
|
const addend = document.getElementById('addend').value; |
|
const contractAddress = 'KT1C8eB3d2VQnuj6ARRT8V4jRUhUuYeNcQK1'; |
|
const params = `{"prim": "Pair", "args": [{"int": "${augend}"}, {"int": "${addend}"}]}`; |
|
|
|
const paramFormat = conseiljs.TezosParameterFormat.Micheline; |
|
let nodeResult = await conseiljs.TezosNodeWriter.sendContractInvocationOperation(tezosNode, keyStore, contractAddress, 0, 50000, '', 1000, 20000, undefined, params, paramFormat); |
|
|
|
const groupid = clearRPCOperationGroupHash(nodeResult.operationGroupID); |
|
console.log(`Injected activation operation with ${groupid}`); |
|
|
|
let conseilResult = await conseiljs.TezosConseilClient.awaitOperationConfirmation(conseilServer, conseilServer.network, groupid, 10, networkBlockTime); |
|
|
|
if (conseilResult.length == 1 && conseilResult[0]['status'] === 'applied') { |
|
console.log(conseilResult[0]); |
|
conseilResult = await conseiljs.TezosConseilClient.getAccount(conseilServer, conseilServer.network, contractAddress); |
|
console.log(conseilResult[0]); |
|
document.getElementById('result').innerText = `= ${conseilResult[0]['storage']}`; |
|
} else if (conseilResult.length == 1 && conseilResult[0]['status'] !== 'applied') { |
|
console.log(`operation ${groupid} failed`); |
|
document.getElementById('result').innerText = '= error'; |
|
console.log(conseilResult[0]); |
|
nodeResult = await conseiljs.TezosNodeReader.getBlock(tezosNode, conseilResult[0]['block_hash']); |
|
console.log(nodeResult); |
|
} else { |
|
console.log(`operation ${groupid} appears to have been rejected`); |
|
} |
|
} |
|
|
|
async function run() { |
|
await initAccount(); |
|
await invokeContract(); |
|
} |
|
</script> |
|
</head> |
|
<body> |
|
<form> |
|
<input type="number" id="augend" value="1" /> + <input type="number" id="addend" value="1" /> <span id="result"></span> |
|
<button onclick="run(); return false;">Run</button> |
|
</form> |
|
</body> |
|
</html> |
Hello Admin,
I think it encounters a front-end bug when I run the above code.
The operation is always successful and can be observed on better call dev (https://better-call.dev/babylon/KT1C8eB3d2VQnuj6ARRT8V4jRUhUuYeNcQK1/operations).
However, I'm not able to get the expected return value.
JS Console says:
"smartPy.html:43 Uncaught (in promise) TypeError: Cannot read property 'storage' of undefined
at invokeContract (smartPy.html:43)
at async run (smartPy.html:56)"
It seems something wrong with
document.getElementById('result').innerText =
= ${conseilResult[0]['storage']};
Can you help me move on for this? Thanks a lot.
Best regards,
Michshell