部署通用合约 (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

If you have your own chain running already (see instruction here), 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

Reference https://docs.cosmwasm.com/tutorials/governance/#submit-proposal for more details on each of the flags and details about contract instantiation/execution.

参考 https://docs.cosmwasm.com/tutorials/governance/#submit-proposal 了解有关每个标志和有关合约实例化/执行的详细信息。

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"}}'

最后更新于