Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: ink contract events (#843)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Solovay <harrysolovay@users.noreply.github.com>
Co-authored-by: Harry Solovay <harrysolovay@gmail.com>
Co-authored-by: T6 <t6@t6.fyi>
  • Loading branch information
4 people authored Apr 7, 2023
1 parent afeb8a6 commit e044efb
Show file tree
Hide file tree
Showing 16 changed files with 861 additions and 1,151 deletions.
3 changes: 1 addition & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
],
"ignorePaths": [
"**/*.wasm",
"frame_metadata/raw_erc20_metadata.json",
"target",
"**/__snapshots__/*.snap",
"**/*.contract",
"examples/smart_contract/metadata.json",
"examples/ink/erc20.json",
"**/*.scale"
]
}
6 changes: 5 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"includes": [
"**.{dockerfile,json,md,toml,ts,tsx}"
],
"excludes": ["target", "util/_artifacts"],
"excludes": [
"target",
"util/_artifacts",
"examples/ink/erc20.json"
],
"plugins": [
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
"https://plugins.dprint.dev/json-0.17.0.wasm",
Expand Down
6 changes: 6 additions & 0 deletions examples/ink/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TODO

Determine a way to _cleanly_ share data (instantiator, contract address) between
ink example envs without necessarily merging the examples. Aka., one should be
able to run them independently / supply an alternative contract and user address
to interaction examples.
Binary file removed examples/ink/code.wasm
Binary file not shown.
13 changes: 7 additions & 6 deletions examples/ink/deploy.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @title Deploy an Ink Smart Contract
* @stability unstable – We intend to work on an Ink provider (for static codegen)
* in the near future. This work will likely entail large changes to the current ink patterns.
*
* Deploying an Ink contract (instantiating) to a production contracts-enabled parachain
* @description Deploying an Ink contract (instantiating) to a production contracts-enabled parachain
* is much the same as any other extrinsic submission.
* @todo utilize `createUsers` instead of `alice`
*/

import { $, alice, ss58 } from "capi"
Expand All @@ -14,15 +14,16 @@ import { chain, System } from "contracts_dev/mod.js"

// Initialize an `InkMetadataRune` with the raw Ink metadata text.
const metadata = InkMetadataRune.fromMetadataText(
Deno.readTextFileSync(new URL(import.meta.resolve("./metadata.json"))),
Deno.readTextFileSync(new URL(import.meta.resolve("./erc20.json"))),
)

// Instantiate `code.wasm` with `alice` and––upon block inclusion––return the
// list of system events specific to this instantiation.
const events = await metadata
.instantiation(chain, {
sender: alice.publicKey,
code: Deno.readFileSync(new URL("./code.wasm", import.meta.url)),
code: Deno.readFileSync(new URL("./erc20.wasm", import.meta.url)),
args: [1_000_000n],
})
.signed(signature({ sender: alice }))
.sent()
Expand All @@ -39,10 +40,10 @@ const events = await metadata
for (const { event } of events) {
if (event.type === "Contracts" && event.value.type === "Instantiated") {
const accountId = event.value.contract
console.log("account id:", accountId)
console.log("Account id:", accountId)
$.assert($.sizedUint8Array(32), accountId)
const address = ss58.encode(System.SS58Prefix, accountId)
console.log("ss58 address:", address)
console.log("Contract ss58 address:", address)
Deno.env.set("SS58_ADDRESS", address)
break
}
Expand Down
Loading

0 comments on commit e044efb

Please sign in to comment.