文檔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
進(jìn)入目錄 contracts 編譯構(gòu)建
./build.sh
https://wallet.testnet.near.org/ 創(chuàng)建一個wallet
安裝 near-cli
npm install -g near-cli
near login --nodeUrl [https://near-testnet.infura.io/v3/ //默認(rèn)的rpc 國內(nèi)可能連不上 可以 注冊infura
會跳轉(zhuǎn)瀏覽器 用剛剛瀏覽器創(chuàng)建的wallet 授權(quán)
創(chuàng)建一個新賬戶部署合約 (部署的合約代碼將存儲在這賬戶下 與合約交互也是與這個賬戶交互)
near create-account learn.jimme3.testnet --masterAccount jimme3.testnet --initialBalance 5 --nodeUrl https://near-testnet.infura.io/v3/上祈。吻谋。并蝗。
--initialBalance 5 是創(chuàng)建賬戶時給賬戶多少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
創(chuàng)建一個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
可能會出現(xiàn)錯誤 ‘learn.jimme3.testnet wouldn't have enough balance to cover storage, required to have 1420661610272280747609512’
多轉(zhuǎn)點near給這個賬戶就行