Sei中文文档(Sei Docs CHN)-by Chainguys
  • 导览(INTRODUCTION)
    • 版权声明(Copyright Notice)
    • 概览 (Overview)
    • Sei 设计空间 (Sei Design Space)
    • DEX 优化 (DEX Optimizations)
    • Sei 生态系统 (Sei Ecosystem)
  • 智能合约和本地开发 (Smart contracts & local development)
    • Sei工具指南 (Sei Tool Guide)
    • 设置一个本地节点 (Set up a local network)
    • 本地 Sei 脚本部署 (Local Sei script deployment)
    • Sei.go
    • CosmWasm合约测试 (CosmWasm Contract Testing)
    • 部署通用合约 (Deploy a generic contract)
    • 部署交易合约 (Deploy an exchange contract)
    • 非完整节点下部署和开发 (Deploy & develop without Full Node)
    • Dex 模块教程 (Dex Module Tutorial)
    • 代币工厂模块教程 (Tokenfactory Module Tutorial)
    • IBC转账 (IBC Transfers)
  • 订单匹配(order match)
    • 并行性 (Parallelism)
    • 资格 (Eligibility)
    • DEX 合约间依赖 (DEX Inter—Contract Dependencies)
    • 白名单商店 (Whitelisted Store)
  • 节点&验证者 (NODES&VALIDATORS)
    • 加入测试网 (Joining Testnets)
    • 更新 (Upgrades)
    • Seinami激励测试网 (Seinami Incentivized Testnet)
      • 加入激励测试网 (Joining Incentivized Testnet)
      • 所有测试任务 (All Testnet Missions)
      • 行为准则 (Code of Conduct)
      • 奖励发放详情 (Rewards Distribution Details)
  • 基础API端点 (Basic API Endpoints)
  • 模块化端点 (Module Endpoints)
  • 状态同步 (Statesync)
  • 恢复操作(Recovery Operations)
  • 治理(GOVERNANCE)
    • 创建提案 (Creating Proposals)
    • 管理质押 (Managing Staking)
    • 对提案投票表决 (Voting on Proposals)
  • 预言机(ORACLE)
    • 预言机参与 (Oracle Participation)
  • 钱包(WALLETS)
    • 钱包集成(Wallet Integration)
    • 转账 (Transfers)
  • 更多(More)
    • 推特(Twitter)
由 GitBook 提供支持
在本页
  • 1.构建 Cosmwasm 合约 (1.Build Cosmwasm contract)
  • 2.上传合约的治理提案 (2.Governance Proposal to Upload a Contract)
  • 3.对治理提案进行投票 (3.Voting on the Governance Proposal)
  • 4.实例化合约 (4.Instantiating contract)
  • 5.执行合约 (5.Execute contract)
  • 6.查询合约 (6.Query contract)
  1. 智能合约和本地开发 (Smart contracts & local development)

部署通用合约 (Deploy a generic contract)

通用合约是指不需要 Sei 的 dex 模块功能的 CosmWasm 合约 A generic contract refers to a CosmWasm contract that does not require functionalities from Sei's dex module

上一页CosmWasm合约测试 (CosmWasm Contract Testing)下一页部署交易合约 (Deploy an exchange contract)

最后更新于2年前

If you have your own chain running already (), the following steps show how to upload your contract to that chain. Sei is a permissioned network, which means that only wasm contracts which are voted on by governance can be deployed to the chain.

如果您已经有自己的链在运行(),请执行以下展示如何将您合约上传到该链步骤。 Sei 是一个许可网络,这意味着只有经过治理投票的 wasm 合约才能部署到链上。

1.构建 Cosmwasm 合约 (1.Build Cosmwasm contract)

Build the image. Note that the following steps are run from your contract directory, so they assume seid is in your $PATH:

构建图像。请注意,以下步骤是从您的合约目录运行的,因此它们假定 seid 在您的 $PATH 中:

cargo build
docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/rust-optimizer:0.12.5

2.上传合约的治理提案 (2.Governance Proposal to Upload a Contract)

Note that on local sei you can skip steps 2 and 3, and directly store the wasm contract like the following:

请注意,在本地 sei 上,您可以跳过第 2 步和第 3 步,直接存储 wasm 合约,如下所示:

seid tx wasm store $CONTRACT_WASM_BINARY -y --from=$ACCOUNT_NAME --chain-id=$CHAIN_ID --gas=10000000 --fees=10000000usei --broadcast-mode=block

Go back to sei-chain repo, and submit a governance proposal to upload the wasm contract.

返回 sei-chain repo,并提交治理提案以上传 wasm 合约。

seid tx gov submit-proposal wasm-store artifacts/$CONTRACTNAME.wasm \

--from $(seid keys show -a $ACCOUNT_NAME) \

--run-as $(seid keys show -a $ACCOUNT_NAME) \

--title "<Enter title proposal title for uploading of wasm contract>" \

--description "<Enter description of proposal and contract>" \

--chain-id sei-chain \

--instantiate-everybody "false" \

--instantiate-only-address $(seid keys show -a $ACCOUNT_NAME) \

--broadcast-mode=block \

--gas=500000 \

--fees=10000000usei

3.对治理提案进行投票 (3.Voting on the Governance Proposal)

Once the governance proposal has been submitted, it must be approved by governance. Find the proposal id and vote on it

治理提案一经提交,必须得到治理层的批准。找到提案 id 并对其进行投票

seid tx gov vote [proposal-id] yes --from $ACCOUNT_NAME

4.实例化合约 (4.Instantiating contract)

Once your proposal is approved, you can instantiate your contract.

一旦您的提案获得批准,您就可以实例化您的合约。

Note in this example the $CONTRACT_ID is 1 and $LABEL is any contract name you want:

注意在这个例子中 $CONTRACT_ID 是 1 并且 $LABEL 是你想要的任何合约名称:

seid tx wasm instantiate $CONTRACT_ID '{}' --chain-id sei-chain --from $ACCOUNT_NAME --gas=4000000 --fees=1000000usei --broadcast-mode=block --label $LABEL --no-admin

Note that the '{}' part is the parameters you pass to instantiate the contract. In this example, the contract takes no parameter so '{}' suffices. For any real world contracts, their instantiation parameters would likely be non-empty. For example, to instantiate Vortex contract, the following parameters need to be used instead (the actual values need/can be changed though):

请注意,'{}' 部分是您传递的实例化合约的参数。在这个例子中,合约没有参数,所以 ''{}'' 就足够了。对于任何现实世界的合约,它们的实例化参数都可能是非空的。例如,要实例化 Vortex 合约,需要使用以下参数(但实际值需要/可以更改):

{"whitelist": ["sei1h9yjz89tl0dl6zu65dpxcqnxfhq60wxx8s5kag"],"use_whitelist":false,"admin":"sei1h9yjz89tl0dl6zu65dpxcqnxfhq60wxx8s5kag","limit_order_fee":{"decimal":"0.0001","negative":false},"market_order_fee":{"decimal":"0.0001","negative":false},"liquidation_order_fee":{"decimal":"0.0001","negative":false}}

You should get a response like the following:

您应该得到如下响应:

height: "2051"

info: ""

logs:

- events:

- attributes:

- key: _contract_address

value: sei1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqdxfzff

- key: code_id

value: "1"

type: instantiate

- attributes:

- key: action

value: /cosmwasm.wasm.v1.MsgInstantiateContract

- key: module

value: wasm

- key: sender

value: cosmos1ep9jyk9kydjz0fhadm7rzy6pc9ga7tdt4d26xn

type: message

log: ""

msg_index: 0

raw_log: '[{"events":[{"type":"instantiate","attributes":[{"key":"_contract_address","value":"cosmos1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqdxfzff"},{"key":"code_id","value":"2"}]},{"type":"message","attributes":[{"key":"action","value":"/cosmwasm.wasm.v1.MsgInstantiateContract"},{"key":"module","value":"wasm"},{"key":"sender","value":"cosmos1ep9jyk9kydjz0fhadm7rzy6pc9ga7tdt4d26xn"}]}]}]'

timestamp: ""

tx: null

txhash: 3033A3673367169693157DF4D22D973A012C03A4FBE452E994E4DE87C8628D23

From the output, you can see that your contract was created at address: sei1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqdxfzff. You will need this address for any contract interaction.

从输出中,你可以看到你的合约是在下面地址创建的:sei1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqdxfzff。您将需要在此地址进行任何合约交互。

5.执行合约 (5.Execute contract)

In this example, we send a UpdatePrice message to update the price of a token on this oracle contract.

在此示例中,我们发送一条“UpdatePrice”消息来更新此预言机合约上代币的“价格”。

{

"update_price": {

"price": "22",

"token_addr": "cosmos16fz9ma2thw3vycca0v9qkezgecusgzza8027z4"

  }

}
seid tx wasm execute $CONTRACT_ADDR '{"update_price": {"price": "22", "token_addr": "$TOKEN_ADDR"}}' --from $ACCOUNT_NAME --gas=4000000 --fees=1000000usei --chain-id sei-chain --broadcast-mode block

6.查询合约 (6.Query contract)

In this example, we send a GetPrice message to get the price of a token on this oracle contract.

在这个例子中,我们发送一个“GetPrice”消息来获取这个预言机合约上一个代币的“价格”。

{

"get_price15": {

"token_addr": "cosmos16fz9ma2thw3vycca0v9qkezgecusgzza8027z4"

}

}

seid query wasm contract-state smart $CONTRACT_ADDR '{"get_price15": {"token_addr": "#TOKEN_ADDR"}}'

Reference for more details on each of the flags and details about contract instantiation/execution.

参考 了解有关每个标志和有关合约实例化/执行的详细信息。

see instruction here
参见此处的说明
https://docs.cosmwasm.com/tutorials/governance/#submit-proposal
https://docs.cosmwasm.com/tutorials/governance/#submit-proposal