Skip to content

Commit ec7de2f

Browse files
authored
Add swap examples to osmojs documentation, fix latex equations (#254)
* feat: try fixing latex * feat: fix latex * feat: add swap example in osmojs ]
1 parent 5fbe24e commit ec7de2f

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

docs/osmojs/README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,56 @@ const fee = {
105105
};
106106
```
107107

108+
### Doing a swap
109+
```js
110+
const signingClient = await getSigningOsmosisClient({
111+
rpcEndpoint: getRpcEndpoint(),
112+
signer: aminoSigner
113+
});
114+
115+
const ibcDenom = pool.poolAssets.find((asset) => {
116+
if (asset.token.denom.startsWith('ibc/')) {
117+
return asset;
118+
}
119+
}).token.denom;
120+
121+
const balanceBefore = await signingClient.getBalance(address, ibcDenom);
122+
123+
const msg =
124+
osmosis.gamm.v1beta1.MessageComposer.withTypeUrl.swapExactAmountIn({
125+
sender: address,
126+
routes: [
127+
{
128+
poolId,
129+
tokenOutDenom: ibcDenom
130+
}
131+
],
132+
tokenIn: {
133+
amount: '200000',
134+
denom: denom
135+
},
136+
tokenOutMinAmount: '100000'
137+
});
138+
139+
const fee = {
140+
amount: [
141+
{
142+
denom,
143+
amount: '100000'
144+
}
145+
],
146+
gas: '550000'
147+
};
148+
149+
const result = await signingClient.signAndBroadcast(
150+
address,
151+
[msg],
152+
fee,
153+
'swap tokens'
154+
);
155+
```
156+
157+
108158
### Initializing the Stargate Client
109159

110160
Use `getSigningOsmosisClient` to get your `SigningStargateClient`, with the Osmosis proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:
@@ -257,9 +307,11 @@ const {
257307
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
258308
```
259309

260-
### Advanced Usage
310+
### Further examples
311+
312+
Examples in [`create-cosmos-app` repo's examples directory](https://github.com/cosmology-tech/create-cosmos-app/tree/main/examples) gives you a great guideline on how osmojs can be used at its full extent.
261313

262-
[documentation](https://github.com/osmosis-labs/osmojs/tree/main/packages/osmojs/docs)
314+
You can also refer to the [osmojs documentation](https://github.com/osmosis-labs/osmojs/tree/main/packages/osmojs/docs) for further documentations on osmojs usage.
263315

264316
## Credits
265317

0 commit comments

Comments
 (0)