# Nibiru激励性测试网第二阶段-智能合约 **Published by:** [Silent ⚛| validator](https://paragraph.com/@exploring/) **Published on:** 2023-04-11 **URL:** https://paragraph.com/@exploring/nibiru-3 ## Content Nibiru是一个基于Cosmos Sdk的DEFI Hub,为衍生品和现货交易提供动力。安全、无需许可、完全上链。其种子轮融资了850万美元,Tribe captital, Republic Crypto 领投,Kraken等机构参投,估值1亿美元。近期,激励测试网第二阶段刚刚开放,明牌有奖励。要KYC。 NIT #2 主要围绕两件事: (1)让 Nibiru Chain 的用户熟悉智能合约部署和交易执行 (2)通过试验更大的验证器集大小来对我们的基础设施进行实时测试。通过这种方式,我们应该对真正去中心化网络的更快出块时间和终结性的一些限制有深刻的理解。 测试网注册:(必须要先注册才能参与激励测试网,第一阶段注册过的朋友可以跳过) https://gleam.io/yW6Ho/nibiru-incentivized-testnet-registration 这次测试网主要有两类任务。本文为智能合约任务的教程。本文需要在命令行操作,有一定难度。如果没有相关经验,可以去完成相对简单的治理任务。 智能合约任务如下:智能合约任务我们主要需要完成以下操作。部署合约实例化合约执行合约前提条件在你的linux系统服务器上安装好nibid程序,可以参考我之前的节点教程。 注:我们不需要运行节点,可以使用别人提供的公共Rpc。 使用公共RPC作为默认RPCnibid config node https://t-nibiru.rpc.utsa.tech:443 备选的公共RPC:https://nibiru-testnet.nodejumper.io:443 https://rpc-t.nibiru.nodestake.top:443 用助记词导入你的钱包(如果你已经导入,请忽略)nibid keys add xxx --recover 部署合约首先下载已经编译好的合约二进制文件wget https://github.com/NibiruChain/cw-nibiru/raw/main/artifacts-cw-plus/cw1_whitelist.wasm 部署合约KEY_NAME=钱包名 CONTRACT_WASM="cw1_whitelist.wasm" nibid tx wasm store $CONTRACT_WASM --from $KEY_NAME --gas=2000000 --fees=200000unibi --chain-id nibiru-itn-1 -y 保存得到的txhash,可以去下面的区块浏览器检查是否成功。也可以用下面的命令可以查询到你刚刚部署的合约的信息。Nibiru (NIBI) Blockchain Explorer - Main Network OverviewGet insights into Nibiru (NIBI) network via Nodes.Guru blockchain explorer. Track the latest block, staking APR, inflation rate, your stake and more.https://nibiru.explorers.guru交易成功txhash=刚刚的txhash nibid query tx $txhash --output json | jq -r '.logs[] | .events[]' 如果交易成功,上面的命令显示如下。query tx显示如下这里得到的code_id在实例化合约的时候有用。但是本教程中暂时用不到。实例化合约这里我们要实例化的是一个cw20代币合约https://github.com/CosmWasm/cw-plus/blob/main/packages/cw20/README.md 这个合约目前已经被存储在链上,它的code id为2257。如果你想实例化自己部署的合约,可以去部署一个cw20合约。 首先,设置一些环境变量code_id=2257 address=你的nibiru钱包地址 KEY_NAME=你的钱包名 创建一个json文件,用于传递实例化时需要的参数tee args.json > /dev/null <<EOF { "name": "Custom CW20 token", "symbol": "CWXX", "decimals": 6, "initial_balances": [ { "address": "${address}", "amount": "555444000" } ], "mint": { "minter": "${address}" }, "marketing": {} } EOF 实例化这个cw20合约nibid tx wasm inst $code_id "$(cat args.json)" --label="mint CWXX contract" --no-admin --from=$KEY_NAME --fees=5000unibi --chain-id nibiru-itn-1 -y 保存这个txhash保存得到的txhash,可以去区块浏览器查询交易是否成功。txhash=刚刚得到的txhash 如果成功,我们可以用如下命令,获取部署成功得到的合约地址。我们执行合约时需要这个地址。contract=$(nibid q tx $txhash --output json| jq -r '.logs[] | .events[0] | .attributes[0] | .value') 输出这个地址echo $contract 执行合约创建一个json文件,用于传递调用合约需要的参数address=任意一个nibiru地址,也可以是自己的地址 KEY_NAME=你的钱包名 tee cw_transfer.json > /dev/null <<EOF { "transfer": { "recipient": "${address}", "amount": "50" } } EOF 这里的参数来源于CW20合约的Cw20ExecuteMsg (这里仅供学习参考,不需要输入)pub enum Cw20ExecuteMsg { /// Transfer is a base message to move tokens to another account without triggering actions Transfer { recipient: String, amount: Uint128 }, // ... } 执行合约nibid tx wasm execute $contract "$(cat cw_transfer.json)" --from $KEY_NAME --gas 8000000 --fees=200000unibi -y --chain-id nibiru-itn-1 -y 保存得到的txhash。可以去区块浏览器查询调用cw20的transfer函数是否成功。 也可以用如下命令检查你这笔交易产生的eventstxhash=刚刚的txhash nibid q tx $txhash --output json| jq -r '.logs[] | .events[]' 显示应该如下执行成功的events至此,我们就完成了Nibiru激励测试网第二阶段的智能合约相关的任务。🔥欢迎关注 https://silentvalidator.com ## Publication Information - [Silent ⚛| validator](https://paragraph.com/@exploring/): Publication homepage - [All Posts](https://paragraph.com/@exploring/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@exploring): Subscribe to updates - [Twitter](https://twitter.com/EthExploring): Follow on Twitter