我如何以编程方式在 Osmosis DEX 上交换/质押?

问题描述 投票:0回答:1

我正在开发一个项目,我需要以编程方式进行一些代币交换。我知道 osmojs。但我的项目不是 JavaScript 或 TypeScript,所以我需要自己进行 RPC 调用。不幸的是,我找不到太多关于如何做到这一点的文档(请原谅我,我对这个和整个 Cosmos 都很陌生),除了 buf.build 文件: a) 自去年以来就没有更新过并且 b) 不完整,例如它没有 poolmanager 模块

此外,我记得 osmosis 文档网站上有一个关于 gRPC 的页面,以及 protobuf 文件的链接,这与我为 Cosmos 所做的事情非常吻合,但是当谷歌搜索“osmosis grpc”时显示的任何链接现在都会导致404 页面。我现在能找到的只是 Tendermint RPC 文档的链接,该文档使用 JSON 进行常规 HTTP 调用,但不知怎的,仍然涉及到 protobuf(还有氨基?在 cosmos sdk 中不是已弃用 protobuf 了吗?说到弃用, Tendermint 整体上并不是 CometBFT 的前身)。我确实通过根据他们命名其余端点的模式进行猜测,设法找到了主网和测试网的 gRPC 端点...

如你所见,我非常迷失,我将不胜感激任何为我指明正确方向的东西:)

我尝试签署

MsgSwapExactAmountIn

MsgSwapExactAmountIn(
        sender: wallet.bech32Address('osmo'),
        routes: [SwapAmountInRoute(poolId: Int64(1), tokenOutDenom: 'uion')],
        tokenIn: Coin(amount: '1000000', denom: 'uosmo'));

并在渗透测试网上用

cosmos.tx.v1beta1.Service.BroadcastTx
广播它,我得到的响应是......关于节点上的 nil 指针的 golang 恐慌,它没有告诉我如何修复我发出的请求,但它足以告诉我我猜这不是怎么做的。得到的答复是:

txhash: 9B4CE689BFB6618ADF048C76C0A3A14244560F1252C6AFD228BC26FC75B6A35C
codespace: undefined
code: 111222
rawLog: recovered: runtime error: invalid memory address or nil pointer dereference
stack:
goroutine 721059165 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x65
github.com/cosmos/cosmos-sdk/baseapp.newDefaultRecoveryMiddleware.func1({0x28158a0, 0x4756310})
    github.com/cosmos/[email protected]/baseapp/recovery.go:71 +0x27
github.com/cosmos/cosmos-sdk/baseapp.newRecoveryMiddleware.func1({0x28158a0?, 0x4756310?})
    github.com/cosmos/[email protected]/baseapp/recovery.go:39 +0x30
github.com/cosmos/cosmos-sdk/baseapp.processRecovery({0x28158a0, 0x4756310}, 0xc04519bb00?)
    github.com/cosmos/[email protected]/baseapp/recovery.go:28 +0x37
github.com/cosmos/cosmos-sdk/baseapp.processRecovery({0x28158a0, 0x4756310}, 0x32b4a20?)
    github.com/cosmos/[email protected]/baseapp/recovery.go:33 +0x5e
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx.func1()
    github.com/cosmos/[email protected]/baseapp/baseapp.go:620 +0xf0
panic({0x28158a0, 0x4756310})
    runtime/panic.go:884 +0x213
math/big.(*Int).Sign(...)
    math/big/int.go:41
cosmossdk.io/math.Int.IsPositive(...)
    cosmossdk.io/[email protected]/int.go:211
github.com/osmosis-labs/osmosis/v20/x/gamm/types.MsgSwapExactAmountIn.ValidateBasic({{0xc05658acf0, 0x2b}, {0xc049082048, 0x1, 0x1}, {{0xc05b120514, 0x5}, {0xc057b6a8c0}}, {0x0}})
    github.com/osmosis-labs/osmosis/v20/x/gamm/types/msgs.go:85 +0x143
github.com/cosmos/cosmos-sdk/baseapp.validateBasicTxMsgs({0xc011d3a720?, 0x1, 0x140?})
    github.com/cosmos/[email protected]/baseapp/baseapp.go:538 +0x8c
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx(0xc001203200, 0x0, {0xc0226a3680, 0x127, 0x140})
    github.com/cosmos/[email protected]/baseapp/baseapp.go:653 +0x425
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx(0xc001203200, {{0xc0226a3680?, 0xc0014dc040?, 0x6bc34e?}, 0x14dc130?})
    github.com/cosmos/[email protected]/baseapp/abci.go:276 +0x135
github.com/tendermint/tendermint/abci/client.(*localClient).CheckTxAsync(0xc000f3ef60, {{0xc0226a3680?, 0xd792e0?, 0xc001210e80?}, 0x14dc2a0?})
    github.com/tendermint/[email protected]/abci/client/local_client.go:104 +0x118
github.com/tendermint/tendermint/proxy.(*appConnMempool).CheckTxAsync(0xc001210e80?, {{0xc0226a3680?, 0xb?, 0x6?}, 0x14dc350?})
    github.com/tendermint/[email protected]/proxy/app_conn.go:126 +0x26
github.com/tendermint/tendermint/mempool/v0.(*CListMempool).CheckTx(0xc0023f8fc0, {0xc0226a3680, 0x127, 0x140}, 0x20?, {0x20?, {0x0?, 0x20?}})
    github.com/tendermint/[email protected]/mempool/v0/clist_mempool.go:254 +0x30d
github.com/tendermint/tendermint/rpc/core.BroadcastTxSync(0xc00133c040, {0xc0226a3680, 0x127, 0x140})
    github.com/tendermint/[email protected]/rpc/core/mempool.go:36 +0xf6
github.com/tendermint/tendermint/rpc/client/local.(*Local).BroadcastTxSync(0xc0440fff38?, {0x0?, 0x0?}, {0xc0226a3680?, 0x48afb20?, 0x0?})
    github.com/tendermint/[email protected]/rpc/client/local/local.go:99 +0x2b
github.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync({{0x0, 0x0, 0x0}, {0x32c40e8, 0xc00133c020}, {0x0, 0x0}, {0x32a62d8, 0xc0010e8810}, 0x0, ...}, ...)
    github.com/cosmos/[email protected]/client/broadcast.go:116 +0x12e
github.com/cosmos/cosmos-sdk/client.Context.BroadcastTx({{0x0, 0x0, 0x0}, {0x32c40e8, 0xc00133c020}, {0x0, 0x0}, {0x32a62d8, 0xc0010e8810}, 0x0, ...}, ...)
    github.com/cosmos/[email protected]/client/broadcast.go:26 +0x85
github.com/cosmos/cosmos-sdk/client.TxServiceBroadcast({_, _}, {{0x0, 0x0, 0x0}, {0x32c40e8, 0xc00133c020}, {0x0, 0x0}, {0x32a62d8, ...}, ...}, ...)
    github.com/cosmos/[email protected]/client/broadcast.go:148 +0x138
github.com/cosmos/cosmos-sdk/x/auth/tx.txServer.BroadcastTx(...)
    github.com/cosmos/[email protected]/x/auth/tx/service.go:153
github.com/cosmos/cosmos-sdk/types/tx._Service_BroadcastTx_Handler.func1({0x329f0f8, 0xc010e001b0}, {0x2a37300?, 0xc052828e40})
    github.com/cosmos/[email protected]/types/tx/service.pb.go:788 +0x78
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).RegisterGRPCServer.func1({0x329f0f8, 0xc08fd6f320}, {0x2a37300, 0xc052828e40}, 0xc052828e60?, 0xc048e2ff38)
    github.com/cosmos/[email protected]/baseapp/grpcserver.go:66 +0x3a5
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1({0x329f0f8?, 0xc08fd6f320?}, {0x2a37300?, 0xc052828e40?})
    github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x3a
github.com/grpc-ecosystem/go-grpc-middleware/recovery.UnaryServerInterceptor.func1({0x329f0f8?, 0xc08fd6f320?}, {0x2a37300?, 0xc052828e40?}, 0x289c740?, 0xc052828e60?)
    github.com/grpc-ecosystem/[email protected]/recovery/interceptors.go:33 +0xc4
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1.1.1({0x329f0f8?, 0xc08fd6f320?}, {0x2a37300?, 0xc052828e40?})
    github.com/grpc-ecosystem/[email protected]/chain.go:25 +0x3a
github.com/grpc-ecosystem/go-grpc-middleware.ChainUnaryServer.func1({0x329f0f8, 0xc08fd6f320}, {0x2a37300, 0xc052828e40}, 0xc0112bca01?, 0xc0112bca88?)
    github.com/grpc-ecosystem/[email protected]/chain.go:34 +0xbe
github.com/cosmos/cosmos-sdk/types/tx._Service_BroadcastTx_Handler({0x29b80e0?, 0xc00a454000}, {0x329f0f8, 0xc08fd6f320}, 0xc048d81860, 0xc08fd6f350)
    github.com/cosmos/[email protected]/types/tx/service.pb.go:790 +0x138
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).RegisterGRPCServer.func2({0x29b80e0, 0xc00a454000}, {0x329f0f8, 0xc08fd6f320}, 0x2ab0d60?, 0xc046a3ea00?)
    github.com/cosmos/[email protected]/baseapp/grpcserver.go:80 +0xdc
google.golang.org/grpc.(*Server).processUnaryRPC(0xc006fda000, {0x32af6a0, 0xc084803680}, 0xc046a3ea00, 0xc00e189fb0, 0xc00a3ab5f0, 0x0)
    google.golang.org/[email protected]/server.go:1210 +0xcbe
google.golang.org/grpc.(*Server).handleStream(0xc006fda000, {0x32af6a0, 0xc084803680}, 0xc046a3ea00, 0x0)
    google.golang.org/[email protected]/server.go:1533 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/[email protected]/server.go:871 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/[email protected]/server.go:869 +0x28a
: panic
grpc osmosis cosmos-sdk
1个回答
0
投票

我建议你使用Python包。 mospy 或 osmosis_protobuf。他们有你需要的一切,而且更简单

© www.soinside.com 2019 - 2024. All rights reserved.