From 06c03678aedadac58255463d9ba074ec8b3a0ae8 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Sun, 6 Oct 2024 04:20:06 +0200 Subject: [PATCH] fix to instantiate contract address and include output log --- README.md | 6 +- logs/instantiateOutput.log | 86 ++++++++++++++++++++ packages/secret-upload-contract/src/index.ts | 49 +++++++---- 3 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 logs/instantiateOutput.log diff --git a/README.md b/README.md index 03373c1..f3f412c 100644 --- a/README.md +++ b/README.md @@ -113,13 +113,13 @@ make build * OPTIONAL - optimize contract code +* Upload and Instantiate ``` yarn run secret:clean:uploadContract yarn run secret:start:uploadContract - -yarn run secret:clean:instantiateContract -yarn run secret:start:instantiateContract ``` +* View logs at ./logs/instantiateOutput.log +* View on Secret Testnet block explorer at https://testnet.ping.pub/secret/ ## Documentation diff --git a/logs/instantiateOutput.log b/logs/instantiateOutput.log new file mode 100644 index 0000000..90bb808 --- /dev/null +++ b/logs/instantiateOutput.log @@ -0,0 +1,86 @@ +Starting deployment... +codeId: 10593 +CODE_HASH: 5ea3b37c0f3b06a621e58327bd7235fd8c323a4a595b095914c5fd2a5511dc93 +params: { + codeId: '10593', + contractCodeHash: '5ea3b37c0f3b06a621e58327bd7235fd8c323a4a595b095914c5fd2a5511dc93' +} +Instantiating contract... +tx: { + height: 7098192, + timestamp: '', + transactionHash: 'C5419257F2ED564093D27F1B73F4EAC4EAABC950EBE590C6B7C9C7B9CC434DEC', + code: 0, + codespace: '', + info: '', + tx: { + '@type': '/cosmos.tx.v1beta1.Tx', + body: { + messages: [Array], + memo: '', + timeout_height: '0', + extension_options: [], + non_critical_extension_options: [] + }, + auth_info: { signer_infos: [Array], fee: [Object] }, + signatures: [ + 'J1Ei+KHikPOXjRfuP1b22UYlxdHJM6TpntR8KFmAEmBPRW2CFou8WFO9Nubg/vAR/bC0cKybR7d9+Rkb77rjNQ==' + ] + }, + rawLog: '[{"events":[{"type":"instantiate","attributes":[{"key":"contract_address","value":"secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9"},{"key":"code_id","value":"10593"}]},{"type":"message","attributes":[{"key":"action","value":"/secret.compute.v1beta1.MsgInstantiateContract"},{"key":"module","value":"compute"},{"key":"sender","value":"secret1am2mk908456twwgehmaua85s6laar4yr3awzzj"},{"key":"contract_address","value":"secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9"}]},{"type":"wasm","attributes":[{"key":"contract_address","value":"secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9"}]}]}]', + jsonLog: [ { events: [Array], msg_index: 0 } ], + arrayLog: [ + { + msg: 0, + type: 'instantiate', + key: 'contract_address', + value: 'secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9' + }, + { msg: 0, type: 'instantiate', key: 'code_id', value: '10593' }, + { + msg: 0, + type: 'message', + key: 'action', + value: '/secret.compute.v1beta1.MsgInstantiateContract' + }, + { msg: 0, type: 'message', key: 'module', value: 'compute' }, + { + msg: 0, + type: 'message', + key: 'sender', + value: 'secret1am2mk908456twwgehmaua85s6laar4yr3awzzj' + }, + { + msg: 0, + type: 'message', + key: 'contract_address', + value: 'secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9' + }, + { + msg: 0, + type: 'wasm', + key: 'contract_address', + value: 'secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9' + } + ], + events: [ + { type: 'coin_spent', attributes: [Array] }, + { type: 'coin_received', attributes: [Array] }, + { type: 'transfer', attributes: [Array] }, + { type: 'message', attributes: [Array] }, + { type: 'tx', attributes: [Array] }, + { type: 'tx', attributes: [Array] }, + { type: 'tx', attributes: [Array] }, + { type: 'message', attributes: [Array] }, + { type: 'instantiate', attributes: [Array] }, + { type: 'wasm', attributes: [Array] }, + { type: 'message', attributes: [Array] } + ], + data: [ + + ], + gasUsed: 43476, + gasWanted: 400000, + ibcResponses: [] +} +SECRET_ADDRESS: secret19kk5wcmxp2alr356emljyr8xp90atndxy3r2c9 diff --git a/packages/secret-upload-contract/src/index.ts b/packages/secret-upload-contract/src/index.ts index 4aa7d85..7e6af69 100644 --- a/packages/secret-upload-contract/src/index.ts +++ b/packages/secret-upload-contract/src/index.ts @@ -50,6 +50,13 @@ async function main () { console.log('balance: ', balance); + type INIT_MSG = { + gateway_address: String, + gateway_hash: String, + gateway_key: String, + count: Number, + }; + type CODE_PARAMS = { codeId: String | undefined, contractCodeHash: String | undefined, @@ -60,21 +67,25 @@ async function main () { let codeId: String | undefined; let contractCodeHash: String | undefined; - - let tx = await secretjs.tx.compute.storeCode( - { - sender: wallet.address, - wasm_byte_code: contract_wasm, - source: "", - builder: "", - }, - { - gasLimit: 5_000_000, - } - ); + let tx: any; + try { + tx = await secretjs.tx.compute.storeCode( + { + sender: wallet.address, + wasm_byte_code: contract_wasm, + source: "", + builder: "", + }, + { + gasLimit: 5_000_000, + } + ); + } catch (e) { + console.log('error: ', e); + } codeId = String( - tx?.arrayLog?.find((log) => log?.type === "message" && log?.key === "code_id")?.value + tx?.arrayLog?.find((log: any) => log?.type === "message" && log?.key === "code_id")?.value ); console.log("codeId: ", codeId); @@ -91,6 +102,7 @@ async function main () { }; let instantiate_contract = async (params: CODE_PARAMS) => { + console.log('params: ', params) let contractAddress; if (!params.codeId || !params.contractCodeHash) { @@ -98,11 +110,13 @@ async function main () { } console.log("Instantiating contract..."); - let initMsg = { + let initMsg: INIT_MSG = { gateway_address: gatewayAddress, gateway_hash: gatewayHash, gateway_key: gatewayPublicKeyBytes, + count: 1, }; + let tx = await secretjs.tx.compute.instantiateContract( { code_id: params.codeId.toString(), @@ -115,6 +129,7 @@ async function main () { gasLimit: 400_000, } ); + console.log('tx: ', tx) //Find the contract_address in the logs contractAddress = tx?.arrayLog?.find( @@ -127,9 +142,9 @@ async function main () { }; // Chain the execution using promises - upload_contract() - .then((res) => { - instantiate_contract(res); + await upload_contract() + .then(async (res) => { + await instantiate_contract(res); }) .catch((error) => { console.error("Error:", error);