-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chore | Refactor] Create & use
withChainApi
(#29)
* Create `withChainApi` example * Refactor most examples * Refactor `ethBridge` examples
- Loading branch information
1 parent
942b635
commit fff0534
Showing
34 changed files
with
172 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,13 @@ | ||
import { createKeyring } from "@trne/utils/createKeyring"; | ||
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents"; | ||
import { getChainApi } from "@trne/utils/getChainApi"; | ||
import { sendExtrinsic } from "@trne/utils/sendExtrinsic"; | ||
import { cleanEnv, str } from "envalid"; | ||
|
||
const env = cleanEnv(process.env, { | ||
CALLER_PRIVATE_KEY: str(), // private key of extrinsic caller | ||
}); | ||
|
||
export async function main() { | ||
const api = await getChainApi("porcini"); | ||
const caller = createKeyring(env.CALLER_PRIVATE_KEY); | ||
import { withChainApi } from "@trne/utils/withChainApi"; | ||
|
||
withChainApi("porcini", async (api, caller) => { | ||
const calls = new Array(10).fill(1).map((n, i) => api.tx.system.remark(`Call ${n + i}`)); | ||
const extrinsic = api.tx.utility.batch(calls); | ||
|
||
const { result } = await sendExtrinsic(extrinsic, caller, { log: console }); | ||
const [event] = filterExtrinsicEvents(result.events, ["Utility.BatchCompleted"]); | ||
|
||
console.log("Extrinsic Result", event.toJSON()); | ||
|
||
await api.disconnect(); | ||
} | ||
|
||
main(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.