mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
scripts: Update for cosmwasm-stargate fees
This commit is contained in:
parent
96e9004148
commit
ed34d57fe5
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env -S yarn node
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { GasPrice, calculateFee } = require("@cosmjs/stargate");
|
||||
const fs = require("fs");
|
||||
|
||||
const endpoint = "http://localhost:26659";
|
||||
@ -21,11 +22,19 @@ const codeMeta = {
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const gasPrice = GasPrice.fromString("0.025ucosm");
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: "wasm" });
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
|
||||
|
||||
const wasm = fs.readFileSync(__dirname + "/contracts/cw1_subkeys.wasm");
|
||||
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload CW1 subkeys contract");
|
||||
const uploadFee = calculateFee(1_500_000, gasPrice);
|
||||
const uploadReceipt = await client.upload(
|
||||
alice.address0,
|
||||
wasm,
|
||||
uploadFee,
|
||||
codeMeta,
|
||||
"Upload CW1 subkeys contract",
|
||||
);
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
const initMsg = {
|
||||
@ -33,16 +42,30 @@ async function main() {
|
||||
mutable: true,
|
||||
};
|
||||
const label = "Subkey test";
|
||||
const { contractAddress } = await client.instantiate(alice.address0, uploadReceipt.codeId, initMsg, label, {
|
||||
memo: `Create a CW1 instance for ${alice.address0}`,
|
||||
admin: alice.address0,
|
||||
});
|
||||
await client.sendTokens(alice.address0, contractAddress, [
|
||||
const instantiateFee = calculateFee(500_000, gasPrice);
|
||||
const { contractAddress } = await client.instantiate(
|
||||
alice.address0,
|
||||
uploadReceipt.codeId,
|
||||
initMsg,
|
||||
label,
|
||||
instantiateFee,
|
||||
{
|
||||
amount: "1000",
|
||||
denom: "ucosm",
|
||||
memo: `Create a CW1 instance for ${alice.address0}`,
|
||||
admin: alice.address0,
|
||||
},
|
||||
]);
|
||||
);
|
||||
const sendFee = calculateFee(80_000, gasPrice);
|
||||
await client.sendTokens(
|
||||
alice.address0,
|
||||
contractAddress,
|
||||
[
|
||||
{
|
||||
amount: "1000",
|
||||
denom: "ucosm",
|
||||
},
|
||||
],
|
||||
sendFee,
|
||||
);
|
||||
console.info(`Contract instantiated for ${alice.address0} subkey at ${contractAddress}`);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env -S yarn node
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { GasPrice, calculateFee } = require("@cosmjs/stargate");
|
||||
const fs = require("fs");
|
||||
|
||||
const endpoint = "http://localhost:26659";
|
||||
@ -63,35 +64,46 @@ const initData = [
|
||||
];
|
||||
|
||||
async function main() {
|
||||
const gasPrice = GasPrice.fromString("0.025ucosm");
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: "wasm" });
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
|
||||
|
||||
const wasm = fs.readFileSync(__dirname + "/contracts/cw3_fixed_multisig.wasm");
|
||||
const uploadFee = calculateFee(1_500_000, gasPrice);
|
||||
const uploadReceipt = await client.upload(
|
||||
alice.address0,
|
||||
wasm,
|
||||
uploadFee,
|
||||
codeMeta,
|
||||
"Upload CW3 fixed multisig contract",
|
||||
);
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
const instantiateFee = calculateFee(500_000, gasPrice);
|
||||
const sendFee = calculateFee(80_000, gasPrice);
|
||||
for (const { admin, initMsg, label } of initData) {
|
||||
const { contractAddress } = await client.instantiate(
|
||||
alice.address0,
|
||||
uploadReceipt.codeId,
|
||||
initMsg,
|
||||
label,
|
||||
instantiateFee,
|
||||
{
|
||||
memo: `Create a CW3 instance for ${initMsg.symbol}`,
|
||||
admin: admin,
|
||||
},
|
||||
);
|
||||
await client.sendTokens(alice.address0, contractAddress, [
|
||||
{
|
||||
amount: "1000",
|
||||
denom: "ucosm",
|
||||
},
|
||||
]);
|
||||
await client.sendTokens(
|
||||
alice.address0,
|
||||
contractAddress,
|
||||
[
|
||||
{
|
||||
amount: "1000",
|
||||
denom: "ucosm",
|
||||
},
|
||||
],
|
||||
sendFee,
|
||||
);
|
||||
console.info(`Contract instantiated for ${label} at ${contractAddress}`);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env -S yarn node
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
|
||||
const fs = require("fs");
|
||||
|
||||
const endpoint = "http://localhost:26659";
|
||||
@ -48,18 +49,34 @@ const inits = [
|
||||
];
|
||||
|
||||
async function main() {
|
||||
const gasPrice = GasPrice.fromString("0.025ucosm");
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: "wasm" });
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet);
|
||||
|
||||
const wasm = fs.readFileSync(__dirname + "/contracts/hackatom.wasm");
|
||||
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload hackatom contract");
|
||||
const uploadFee = calculateFee(1_500_000, gasPrice);
|
||||
const uploadReceipt = await client.upload(
|
||||
alice.address0,
|
||||
wasm,
|
||||
uploadFee,
|
||||
codeMeta,
|
||||
"Upload hackatom contract",
|
||||
);
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
const instantiateFee = calculateFee(500_000, gasPrice);
|
||||
for (const { label, msg, admin } of inits) {
|
||||
const { contractAddress } = await client.instantiate(alice.address0, uploadReceipt.codeId, msg, label, {
|
||||
memo: `Create a hackatom instance in deploy_hackatom.js`,
|
||||
admin: admin,
|
||||
});
|
||||
const { contractAddress } = await client.instantiate(
|
||||
alice.address0,
|
||||
uploadReceipt.codeId,
|
||||
msg,
|
||||
label,
|
||||
instantiateFee,
|
||||
{
|
||||
memo: `Create a hackatom instance in deploy_hackatom.js`,
|
||||
admin: admin,
|
||||
},
|
||||
);
|
||||
console.info(`Contract instantiated at ${contractAddress}`);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,12 @@ const { coins } = require("@cosmjs/amino");
|
||||
const { Random } = require("@cosmjs/crypto");
|
||||
const { Bech32 } = require("@cosmjs/encoding");
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const { assertIsBroadcastTxSuccess, SigningStargateClient } = require("@cosmjs/stargate");
|
||||
const {
|
||||
assertIsBroadcastTxSuccess,
|
||||
SigningStargateClient,
|
||||
calculateFee,
|
||||
GasPrice,
|
||||
} = require("@cosmjs/stargate");
|
||||
|
||||
const rpcUrl = "http://localhost:26659";
|
||||
const prefix = "wasm";
|
||||
@ -20,8 +25,9 @@ async function main() {
|
||||
const client = await SigningStargateClient.connectWithSigner(rpcUrl, wallet, { prefix: prefix });
|
||||
const recipient = Bech32.encode(prefix, Random.getBytes(20));
|
||||
const amount = coins(226644, "ucosm");
|
||||
const fee = calculateFee(80_000, GasPrice.fromString("0.025ucosm"));
|
||||
const memo = "Ensure chain has my pubkey";
|
||||
const sendResult = await client.sendTokens(faucet.address0, recipient, amount, memo);
|
||||
const sendResult = await client.sendTokens(faucet.address0, recipient, amount, fee, memo);
|
||||
assertIsBroadcastTxSuccess(sendResult);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user