near rust 合约

文档https://docs.near.org/sdk/rust/introduction
安装rust略
rustup target add wasm32-unknown-unknown
从near-examples随便找一个rust项目克隆

git clone https://github.com/near-examples/factory-rust.git
进入目录 contracts 编译构建
./build.sh
https://wallet.testnet.near.org/ 创建一个wallet
安装 near-cli
npm install -g near-cli
near login --nodeUrl [https://near-testnet.infura.io/v3/ //默认的rpc 国内可能连不上 可以 注册infura
会跳转浏览器 用刚刚浏览器创建的wallet 授权

创建一个新账户部署合约 (部署的合约代码将存储在这账户下 与合约交互也是与这个账户交互)

near create-account learn.jimme3.testnet --masterAccount jimme3.testnet --initialBalance 5 --nodeUrl https://near-testnet.infura.io/v3/。。。
--initialBalance 5 是创建账户时给账户多少near
部署合约 刚刚./build.sh 的时候会生成一个 token_factory.wasm 文件
near deploy --wasmFile D:\code\oken-factory\contracts\factory\res\token_factory.wasm --accountId learn.jimme3.testnet

部署成功后先初始化
near call learn.jimme3.testnet new --accountId learn.jimme3.testnet --nodeUrl https://near-testnet.infura.io/v3/。。。

初始化后就可以与合约交互了
查询
near view learn.jimme3.testnet get_required_deposit '{"args":{"owner_id":"jimme3.testnet","total_supply":"10000000000000","metadata":{"spec":"ft-1.0.0","name":"my_first","symbol":"MF","icon":"","reference":"","reference_hash":"OGhhthV17BOUoIiY/aRARm7h2abtQ4uhAu7b3zIkkPQ=","decimals":8}},"account_id":"jimme3.testnet"}' --nodeUrl https://near-testnet.infura.io/v3/。。。

storage_deposit 为payable 方法 与合约交互 带上 0.8 near
near call learn.jimme3.testnet storage_deposit --deposit 0.8 --accountId learn.jimme3.testnet --nodeUrl https://near-testnet.infura.io/v3/206290119a334a5da1bf58de65f2e634

创建一个token
near call learn.jimme3.testnet create_token '{"args":{"owner_id":"jimme3.testnet","total_supply":"10000000000000","metadata":{"spec":"ft-1.0.0","name":"my_first","symbol":"MF","icon":"","reference":"","reference_hash":"OGhhthV17BOUoIiY/aRARm7h2abtQ4uhAu7b3zIkkPQ=","decimals":8}}}' --gas=80000000000000 --accountId learn.jimme3.testnet --nodeUrl https://near-testnet.infura.io/v3/206290119a334a5da1bf58de65f2e634

--gas=80000000000000 指定 gas

可能会出现错误 ‘learn.jimme3.testnet wouldn't have enough balance to cover storage, required to have 1420661610272280747609512’

多转点near给这个账户就行

你可能感兴趣的:(near rust 合约)