Skip to content

Commit 143f640

Browse files
committed
osmosis examples
1 parent 9a643a4 commit 143f640

File tree

5 files changed

+306
-65
lines changed

5 files changed

+306
-65
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'package:blockchain_utils/binary/utils.dart';
2+
import 'package:blockchain_utils/bip/bip/bip39/bip39_seed_generator.dart';
3+
import 'package:blockchain_utils/bip/bip/bip44/bip44_base.dart';
4+
import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_coins.dart';
5+
import 'package:blockchain_utils/bip/mnemonic/mnemonic.dart';
6+
import 'package:cosmos_sdk/cosmos_sdk.dart';
7+
import 'package:example/provider.dart';
8+
9+
void main() async {
10+
final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
11+
"this dove indoor skin shed gap east welcome gift buffalo silent high"))
12+
.generate();
13+
final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).deriveDefaultPath;
14+
final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
15+
16+
final publickey = privateKey.toPublicKey();
17+
18+
final provider = TendermintProvider(
19+
TendermintHTTPProvider(url: "https://rpc.testnet.osmosis.zone/"));
20+
21+
final message = OsmosisTokenFactoryMsgCreateDenom(
22+
sender: publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address,
23+
subdenom: "MRT");
24+
25+
/// Querying account info from the blockchain
26+
final accountInfo = await provider.request(TendermintRequestAbciQuery(
27+
request: QueryAccountInfoRequest(
28+
publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));
29+
30+
/// Querying the latest block information
31+
final latestBlock = await provider.request(
32+
TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
33+
34+
/// Creating authentication info for transaction
35+
final authInfo = AuthInfo(
36+
signerInfos: [
37+
SignerInfo(
38+
publicKey: publickey,
39+
modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
40+
sequence: accountInfo.info.sequence)
41+
],
42+
fee: Fee(amount: [
43+
Coin(
44+
denom: "uosmo",
45+
amount: BigInt.from(1000000),
46+
)
47+
], gasLimit: BigInt.from(2000000)));
48+
49+
final txbody = TXBody(messages: [message]);
50+
51+
/// Creating a signable document for the transaction
52+
final SignDoc signDoc = SignDoc(
53+
bodyBytes: txbody.toBuffer(),
54+
authInfoBytes: authInfo.toBuffer(),
55+
chainId: latestBlock.block!.header.chainId,
56+
accountNumber: accountInfo.info.accountNumber);
57+
58+
final sign = privateKey.sign(signDoc.toBuffer());
59+
60+
final txRaw = TxRaw(
61+
bodyBytes: txbody.toBuffer(),
62+
authInfoBytes: authInfo.toBuffer(),
63+
signatures: [sign]);
64+
65+
await provider.request(TendermintRequestBroadcastTxCommit(
66+
BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
67+
68+
/// https://celatone.osmosis.zone/osmo-test-5/txs/710730140C2054BC7E626CD80088DE46A23CA45C795B830E81609A28699F4F12
69+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'package:blockchain_utils/binary/utils.dart';
2+
import 'package:blockchain_utils/bip/bip/bip39/bip39_seed_generator.dart';
3+
import 'package:blockchain_utils/bip/bip/bip44/bip44_base.dart';
4+
import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_coins.dart';
5+
import 'package:blockchain_utils/bip/mnemonic/mnemonic.dart';
6+
import 'package:cosmos_sdk/cosmos_sdk.dart';
7+
import 'package:example/provider.dart';
8+
9+
void main() async {
10+
final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
11+
"this dove indoor skin shed gap east welcome gift buffalo silent high"))
12+
.generate();
13+
final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).deriveDefaultPath;
14+
// print("addr ${bip44.publicKey.toAddress}");
15+
final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
16+
17+
final publickey = privateKey.toPublicKey();
18+
// print(pr.toPublicKey().toAddresss(hrp: "osmo"));
19+
20+
final provider = TendermintProvider(
21+
TendermintHTTPProvider(url: "https://rpc.testnet.osmosis.zone/"));
22+
23+
final message = OsmosisTokenFactoryMsgMint(
24+
sender: publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address,
25+
amount: Coin(
26+
denom: "factory/osmo1htg7dmhelazdsmuwm9ngtg0tpe82006ugka49q/MRT",
27+
amount: BigInt.from(123123123123123)));
28+
29+
/// Querying account info from the blockchain
30+
final accountInfo = await provider.request(TendermintRequestAbciQuery(
31+
request: QueryAccountInfoRequest(
32+
publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));
33+
34+
/// Querying the latest block information
35+
final latestBlock = await provider.request(
36+
TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
37+
38+
final authInfo = AuthInfo(
39+
signerInfos: [
40+
SignerInfo(
41+
publicKey: publickey,
42+
modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
43+
sequence: accountInfo.info.sequence)
44+
],
45+
fee: Fee(amount: [
46+
Coin(
47+
denom: "uosmo",
48+
amount: BigInt.from(100000),
49+
)
50+
], gasLimit: BigInt.from(2000000)));
51+
52+
final txbody = TXBody(messages: [message]);
53+
54+
/// Creating a signable document for the transaction
55+
final SignDoc signDoc = SignDoc(
56+
bodyBytes: txbody.toBuffer(),
57+
authInfoBytes: authInfo.toBuffer(),
58+
chainId: latestBlock.block!.header.chainId,
59+
accountNumber: accountInfo.info.accountNumber);
60+
61+
/// Signing the document with the private key
62+
final sign = privateKey.sign(signDoc.toBuffer());
63+
64+
final txRaw = TxRaw(
65+
bodyBytes: txbody.toBuffer(),
66+
authInfoBytes: authInfo.toBuffer(),
67+
signatures: [sign]);
68+
69+
await provider.request(TendermintRequestBroadcastTxCommit(
70+
BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
71+
72+
/// https://celatone.osmosis.zone/osmo-test-5/txs/B7F3780394D5E0530F0B14293B4406D3051E38F2D9B05B45EE6FD3230E05B50A
73+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:blockchain_utils/binary/utils.dart';
2+
import 'package:blockchain_utils/bip/bip/bip39/bip39_seed_generator.dart';
3+
import 'package:blockchain_utils/bip/bip/bip44/bip44_base.dart';
4+
import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_coins.dart';
5+
import 'package:blockchain_utils/bip/mnemonic/mnemonic.dart';
6+
import 'package:cosmos_sdk/cosmos_sdk.dart';
7+
import 'package:example/provider.dart';
8+
9+
/// final privateKey2 = CosmosSecp256K1PrivateKey.fromBytes(
10+
/// Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).privateKey.raw);
11+
/// final publickey2 = privateKey2.toPublicKey();
12+
13+
/// osmo1wqzpmju4gl0kcajhjls6ufrqecaedxm9udt80k
14+
void main() async {
15+
final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
16+
"this dove indoor skin shed gap east welcome gift buffalo silent high"))
17+
.generate();
18+
final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).deriveDefaultPath;
19+
20+
final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
21+
22+
final publickey = privateKey.toPublicKey();
23+
// print(pr.toPublicKey().toAddresss(hrp: "osmo"));
24+
25+
final provider = TendermintProvider(
26+
TendermintHTTPProvider(url: "https://rpc.testnet.osmosis.zone/"));
27+
28+
final message = MsgSend(
29+
fromAddress: publickey.toAddresss(hrp: CosmosAddrConst.osmosis),
30+
toAddress:
31+
CosmosBaseAddress("osmo1wqzpmju4gl0kcajhjls6ufrqecaedxm9udt80k"),
32+
amount: [
33+
Coin(
34+
denom: "factory/osmo1htg7dmhelazdsmuwm9ngtg0tpe82006ugka49q/MRT",
35+
amount: BigInt.from(100))
36+
]);
37+
// print(
38+
// "address ${publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address}");
39+
40+
/// Querying account info from the blockchain
41+
final accountInfo = await provider.request(TendermintRequestAbciQuery(
42+
request: QueryAccountInfoRequest(
43+
publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));
44+
45+
/// Querying the latest block information
46+
final latestBlock = await provider.request(
47+
TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
48+
49+
/// Creating authentication info for transaction
50+
final authInfo = AuthInfo(
51+
signerInfos: [
52+
SignerInfo(
53+
publicKey: publickey,
54+
modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
55+
sequence: accountInfo.info.sequence)
56+
],
57+
fee: Fee(amount: [
58+
Coin(
59+
denom: "uosmo",
60+
amount: BigInt.from(100000),
61+
)
62+
], gasLimit: BigInt.from(2000000)));
63+
64+
final txbody = TXBody(messages: [message]);
65+
66+
/// Creating a signable document for the transaction
67+
final SignDoc signDoc = SignDoc(
68+
bodyBytes: txbody.toBuffer(),
69+
authInfoBytes: authInfo.toBuffer(),
70+
chainId: latestBlock.block!.header.chainId,
71+
accountNumber: accountInfo.info.accountNumber);
72+
73+
/// Signing the document with the private key
74+
final sign = privateKey.sign(signDoc.toBuffer());
75+
76+
final txRaw = TxRaw(
77+
bodyBytes: txbody.toBuffer(),
78+
authInfoBytes: authInfo.toBuffer(),
79+
signatures: [sign]);
80+
81+
await provider.request(TendermintRequestBroadcastTxCommit(
82+
BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
83+
84+
/// https://celatone.osmosis.zone/osmo-test-5/txs/7C66B231A02BE52E2E42127A6BAAC35C24AEC35519E3FED4545982BEE781EBA8
85+
}

example/test/widget_test.dart

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,94 @@
66
// import 'package:cosmos_sdk/cosmos_sdk.dart';
77
// import 'package:example/provider.dart';
88

9+
// /// final privateKey2 = CosmosSecp256K1PrivateKey.fromBytes(
10+
// /// Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).privateKey.raw);
11+
// /// final publickey2 = privateKey2.toPublicKey();
12+
13+
// /// osmo1wqzpmju4gl0kcajhjls6ufrqecaedxm9udt80k
914
// void main() async {
1015
// final seedBytes = Bip39SeedGenerator(Mnemonic.fromString(
1116
// "this dove indoor skin shed gap east welcome gift buffalo silent high"))
1217
// .generate();
1318
// final bip44 = Bip44.fromSeed(seedBytes, Bip44Coins.osmosis).deriveDefaultPath;
14-
// // print("addr ${bip44.publicKey.toAddress}");
19+
1520
// final privateKey = CosmosSecp256K1PrivateKey.fromBytes(bip44.privateKey.raw);
1621

1722
// final publickey = privateKey.toPublicKey();
1823
// // print(pr.toPublicKey().toAddresss(hrp: "osmo"));
1924

2025
// final provider = TendermintProvider(
2126
// TendermintHTTPProvider(url: "https://rpc.testnet.osmosis.zone/"));
22-
// final b = await provider.request(TendermintRequestAbciQuery(
23-
// request: OmosisEpochsQueryCurrentEpochRequest("day")));
24-
// print("b $b");
25-
// // print("b $b");
26-
// // return;
27+
28+
// final message = MsgSend(
29+
// fromAddress: publickey.toAddresss(hrp: CosmosAddrConst.osmosis),
30+
// toAddress:
31+
// CosmosBaseAddress("osmo1wqzpmju4gl0kcajhjls6ufrqecaedxm9udt80k"),
32+
// amount: [
33+
// Coin(
34+
// denom: "factory/osmo1htg7dmhelazdsmuwm9ngtg0tpe82006ugka49q/MRT",
35+
// amount: BigInt.from(100))
36+
// ]);
37+
// // print(
38+
// // "address ${publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address}");
39+
40+
// /// Querying account info from the blockchain
41+
// final accountInfo = await provider.request(TendermintRequestAbciQuery(
42+
// request: QueryAccountInfoRequest(
43+
// publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));
44+
45+
// /// Querying the latest block information
46+
// final latestBlock = await provider.request(
47+
// TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
48+
49+
// final accountBalances = await provider.request(TendermintRequestAbciQuery(
50+
// request: QueryAllBalancesRequest(
51+
// address: publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));
52+
53+
// // print("balances $accountBalances");
2754
// // return;
28-
// // final latestBlock = await provider.request(
29-
// // TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
30-
// // final coinQuery = await provider.request(
31-
// // TendermintRequestAbciQuery(request: const QueryDenomsMetadataRequest()));
32-
33-
// // /// Querying account info from the blockchain
34-
// // final accountInfo = await provider.request(TendermintRequestAbciQuery(
35-
// // request: QueryAccountInfoRequest(publickey.toAddresss(hrp: "osmo"))));
36-
37-
// // /// Querying the latest block information
38-
// // final latestBlock = await provider.request(
39-
// // TendermintRequestAbciQuery(request: const GetLatestBlockRequest()));
40-
41-
// // /// Creating authentication info for transaction
42-
// // final authInfo = AuthInfo(
43-
// // signerInfos: [
44-
// // SignerInfo(
45-
// // publicKey: publickey,
46-
// // modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
47-
// // sequence: accountInfo.info.sequence)
48-
// // ],
49-
// // fee: Fee(amount: [
50-
// // Coin(
51-
// // denom: "uosmo",
52-
// // amount: BigInt.from(1000),
53-
// // )
54-
// // ], gasLimit: BigInt.from(200000)));
55-
56-
// // /// Creating a transaction message to send tokens
57-
// // final message = MsgSend(
58-
// // fromAddress: publickey.toAddresss(hrp: "osmo"),
59-
// // toAddress:
60-
// // CosmosBaseAddress("osmo1g5f2d3w3065usfc5fsflafa5jacp090u6pzyx5"),
61-
// // amount: [Coin(denom: "uosmo", amount: BigInt.from(8098000))]);
62-
63-
// // /// Creating transaction body with the message
64-
// // final txbody = TXBody(messages: [message]);
65-
66-
// // /// Creating a signable document for the transaction
67-
// // final SignDoc signDoc = SignDoc(
68-
// // bodyBytes: txbody.toBuffer(),
69-
// // authInfoBytes: authInfo.toBuffer(),
70-
// // chainId: latestBlock.block!.header.chainId,
71-
// // accountNumber: accountInfo.info.accountNumber);
72-
73-
// // /// Signing the document with the private key
74-
// // final sign = privateKey.sign(signDoc.toBuffer());
75-
76-
// // /// Creating a raw transaction with body, authentication info, and signature
77-
// // final txRaw = TxRaw(
78-
// // bodyBytes: txbody.toBuffer(),
79-
// // authInfoBytes: authInfo.toBuffer(),
80-
// // signatures: [sign]);
81-
82-
// // /// Broadcasting the raw transaction to the network
83-
// // final r = await provider.request(TendermintRequestBroadcastTxCommit(
84-
// // BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
85-
// // print("result $r");
55+
56+
// /// Creating authentication info for transaction
57+
// final authInfo = AuthInfo(
58+
// signerInfos: [
59+
// SignerInfo(
60+
// publicKey: publickey,
61+
// modeInfo: const ModeInfo(ModeInfoSignle(SignMode.signModeDirect)),
62+
// sequence: accountInfo.info.sequence)
63+
// ],
64+
// fee: Fee(amount: [
65+
// Coin(
66+
// denom: "uosmo",
67+
// amount: BigInt.from(100000),
68+
// )
69+
// ], gasLimit: BigInt.from(2000000)));
70+
71+
// final txbody = TXBody(messages: [message]);
72+
73+
// /// Creating a signable document for the transaction
74+
// final SignDoc signDoc = SignDoc(
75+
// bodyBytes: txbody.toBuffer(),
76+
// authInfoBytes: authInfo.toBuffer(),
77+
// chainId: latestBlock.block!.header.chainId,
78+
// accountNumber: accountInfo.info.accountNumber);
79+
80+
// /// Signing the document with the private key
81+
// final sign = privateKey.sign(signDoc.toBuffer());
82+
83+
// final txRaw = TxRaw(
84+
// bodyBytes: txbody.toBuffer(),
85+
// authInfoBytes: authInfo.toBuffer(),
86+
// signatures: [sign]);
87+
88+
// // final txForSimulate =
89+
// // Tx(body: txbody, authInfo: authInfo, signatures: [sign]);
90+
91+
// // final simulateRequest = await provider.request(TendermintRequestAbciQuery(
92+
// // request: SimulateRequest(txForSimulate.toBuffer())));
93+
// // print("simulate $simulateRequest");
94+
// final resp = await provider.request(TendermintRequestBroadcastTxCommit(
95+
// BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
96+
// print("resp $resp");
97+
98+
// /// https://celatone.osmosis.zone/osmo-test-5/txs/7C66B231A02BE52E2E42127A6BAAC35C24AEC35519E3FED4545982BEE781EBA8
8699
// }
87-
void main() {}

lib/src/address/address/address_const.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ class CosmosAddrConst {
1818
static const String thor = "thor";
1919

2020
static const String kujira = "kujira";
21+
22+
static const String osmosis = "osmo";
2123
}

0 commit comments

Comments
 (0)