Start document upload of mask, and instantiate
This commit is contained in:
parent
e9aaa60e82
commit
e5d89f1fad
61
packages/cli/MASK.md
Normal file
61
packages/cli/MASK.md
Normal file
@ -0,0 +1,61 @@
|
||||
# Using the Mask
|
||||
|
||||
This assumes you have already run through the sample in the [README](./README.md).
|
||||
And have an initialized account. You can use any connect method (sharing with cli,
|
||||
customize blockchain) if you want. We will show uploading mask and using it
|
||||
on the Demo Net.
|
||||
|
||||
Start with `./bin/cosmwasm-cli --init examples/helpers.ts examples/mask.ts`
|
||||
(note the addition of `examples/mask.ts`)
|
||||
|
||||
Ensure the account is set up:
|
||||
|
||||
```ts
|
||||
// you can hand-copy a mnemonic here, but this is easiest for reuse between sessions
|
||||
// it creates a random one first time, then reads it in the future
|
||||
const mnemonic = loadOrCreateMnemonic("foo.key");
|
||||
const {address, client} = await connect(mnemonic, {});
|
||||
address
|
||||
client.getAccount();
|
||||
```
|
||||
|
||||
We will use [mask v0.1.0](https://github.com/CosmWasm/cosmwasm-examples/tree/mask-0.1.0/mask),
|
||||
the hash is [defined here](https://github.com/CosmWasm/cosmwasm-examples/blob/mask-0.1.0/mask/hash.txt):
|
||||
`1f50bbff503fd9c7bfe713bbf42b309cf88ef299fa76e0242051c9a7e25649a3`. The following will check if
|
||||
it is already uploaded:
|
||||
|
||||
```ts
|
||||
const hash = "1f50bbff503fd9c7bfe713bbf42b309cf88ef299fa76e0242051c9a7e25649a3"
|
||||
client.getCodes().then(codes => codes.filter(x => x.checksum === hash))
|
||||
```
|
||||
|
||||
If it is not uploaded, we will upload it:
|
||||
|
||||
```ts
|
||||
// Either download the code
|
||||
const wasmUrl = "https://github.com/CosmWasm/cosmwasm-examples/blob/mask-0.1.0/mask/contract.wasm?raw=true";
|
||||
const wasm = await downloadWasm(wasmUrl);
|
||||
|
||||
// Or load from local file
|
||||
const wasmFile = ".../cosmwasm-examples/mask/contract.wasm"
|
||||
const wasm = fs.readFileSync(wasmFile);
|
||||
|
||||
// Then upload it
|
||||
const up = await client.upload(wasm, { source: "https://crates.io/api/v1/crates/cw-mask/0.1.0/download", builder: "confio/cosmwasm-opt:0.7.3"});
|
||||
up
|
||||
up.logs[0].events[0]
|
||||
```
|
||||
|
||||
Now, make an instance (as above):
|
||||
|
||||
```ts
|
||||
// get the proper codeId
|
||||
const codes = await client.getCodes()
|
||||
const codeId = codes.filter(x => x.checksum === hash).map(x => x.id)[0]
|
||||
|
||||
// instantiate one contract
|
||||
const maskResp = await client.instantiate(codeId, {}, "My Mask");
|
||||
const mask = maskResp.contractAddress;
|
||||
```
|
||||
|
||||
TODO: using it with proper types
|
||||
@ -242,7 +242,12 @@ const {address, client} = await connect(mnemonic, regenOptions);
|
||||
address
|
||||
```
|
||||
|
||||
Once you have access to the same key as in the cli, you can use those tokens to play with contracts
|
||||
Once you have access to the same key as in the cli, you can use those tokens to play with contracts.
|
||||
|
||||
## Diving into Contracts
|
||||
|
||||
Check out the [mask documentation](./MASK.md) to view how to use some custom helpers to upload code and use non-trivial contracts
|
||||
with proper types.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@ -93,3 +93,14 @@ const randomAddress = async (prefix: string): Promise<string> => {
|
||||
const pubkey = encodeSecp256k1Pubkey(pen.pubkey);
|
||||
return pubkeyToAddress(pubkey, prefix);
|
||||
}
|
||||
|
||||
const downloadWasm = async (url: string): Promise<Uint8Array> => {
|
||||
const r = await axios.get(url, { responseType: "arraybuffer"});
|
||||
if (r.status !== 200) {
|
||||
throw new Error(`Download error: ${r.status}`);
|
||||
}
|
||||
return r.data;
|
||||
}
|
||||
|
||||
const getAttibute = (logs: readonly logs.Log[], key: string): string|undefined =>
|
||||
logs[0].events[0].attributes.find(x => x.key == key)?.value
|
||||
|
||||
0
packages/cli/examples/mask.ts
Normal file
0
packages/cli/examples/mask.ts
Normal file
@ -34,6 +34,7 @@ export function main(originalArgs: readonly string[]): void {
|
||||
[
|
||||
"encodeSecp256k1Pubkey",
|
||||
"encodeSecp256k1Signature",
|
||||
"logs",
|
||||
"makeSignBytes",
|
||||
"marshalTx",
|
||||
"Pen",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user