Skip to content

Instantly share code, notes, and snippets.

View jimmychu0807's full-sized avatar
🎯
Focusing

Jimmy Chu jimmychu0807

🎯
Focusing
View GitHub Profile
@jimmychu0807
jimmychu0807 / Markdium-Shell.bash
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
mkdir ui-tutorial
cd ui-tutorial
# -- 安裝 Rust 及 Substrate
# 更詳細的安裝指引可參考:
# https://substrate.dev/docs/en/overview/getting-started
curl https://getsubstrate.io -sSf | bash
# -- 下載 Substrate Node Template,編譯並運行起來
git clone https://github.com/substrate-developer-hub/substrate-node-template node-template
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
let unsubscribe;
api.query.templateModule.something(function(val) {
// 回調函數
// 在這裡設置 UI 里使用的變量。
}).then(unsub => {
//取消訂閱函數
unsubscribe = unsub;
})
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
import { useSubstrate } from './substrate-lib';
import { TxButton } from './substrate-lib/components';
//...
function main (props) {
//...
return (
<Grid.Column>
<h1>Template Module</h1>
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
{
//外部交易函數
// 這個參看回 `pallet/template/src/lib.rs` 的名字
tx: api.tx.<模塊名字>.<extrinsic 名字>
//外部交易函數的輸入參數數組
params: [...]
}
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
useEffect(() => {
let unsubscribe;
api.query.templateModule.something(newValue => {
// The storage value is an Option<u32>
// So we have to check whether it is None first
// There is also unwrapOr
if (newValue.isNone) {
setCurrentValue('<None>');
} else {
setCurrentValue(newValue.unwrap().toNumber());
@jimmychu0807
jimmychu0807 / Markdium-JSON.json
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
{
"PROVIDER_SOCKET": "ws://<你的 ws/wss 地址>"
}
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:06
Markdium-用 Substrate Front-end Template 輕鬆打造你的 React 應用
api.tx.my_pallet.dispatch_call(params).signAndSend(accountPair, 回調函數)
@jimmychu0807
jimmychu0807 / Markdium-javascript.js
Created March 4, 2020 12:03
Markdium-用 Substrate Front-end Template 轻松打造你的 React 应用
const val = await api.query.templateModule.something();
@jimmychu0807
jimmychu0807 / Markdium-JSONLD.jsonld
Created March 4, 2020 12:03
Markdium-用 Substrate Front-end Template 轻松打造你的 React 应用
{
...,
"CUSTOM_TYPES": {
"Price": {
"dollars": "u32",
"cents": "u32",
"currency": "Vec"
},
}
}
@jimmychu0807
jimmychu0807 / Markdium-rust.rs
Created March 4, 2020 12:03
Markdium-用 Substrate Front-end Template 轻松打造你的 React 应用
// This module's storage items.
decl_storage! {
trait Store for Module as TemplateModule {
Something get(fn something): Option;
}
}