near nft example

文章目录

先决条件

  • 安装了near-cli

获取example代码并编译wasm

git clone https://github.com/near-examples/NFT
cd NFT
./build.sh

检查res下的wasm是否生成

创建账户

浏览器进入https://wallet.testnet.near.org/,输入用户名pld2(替换成你自己的用户名),保存好助记词

登录

登录方式一

near login

登录方式二

没有浏览器的登录方式,创建access key

near generate-key pld2.testnet --seedPhrase="助记词"

检查~/.near-credentials/testnet/pld2.testnet.json文件是否创建好

部署智能合约

为了更易于复制/粘贴,我们将为我们的帐户 ID 设置一个环境变量。

ID=pld2.testnet

检查环境变量是否生效

echo $ID

执行部署

near deploy --wasmFile res/non_fungible_token.wasm --accountId $ID

返回内容如下

Starting deployment. Account id: pld2.testnet, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: res/non_fungible_token.wasm
Transaction Id HTFC3FbEc3jg3yFM4oShQdQRcg1S3Ts6Mmx8LKvWNWxk
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/HTFC3FbEc3jg3yFM4oShQdQRcg1S3Ts6Mmx8LKvWNWxk
Done deploying to pld2.testnet

区块浏览器tx:
near nft example

初始化元数据

near call $ID new_default_meta '{"owner_id": "'$ID'"}' --accountId $ID

返回内容如下

Scheduling a call: pld2.testnet.new_default_meta({"owner_id": "pld2.testnet"})
Transaction Id CNBLQC35snZLnUzc3VQMBZysUTc8HxjXtsL4cEJaSo3
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/CNBLQC35snZLnUzc3VQMBZysUTc8HxjXtsL4cEJaSo3

区块浏览器tx:
near nft example

查看元数据

near view $ID nft_metadata

铸造第一个nft令牌

near call $ID nft_mint '{"token_id": "0", "receiver_id": "'$ID'", "token_metadata": { "title": "Olympus Mons", "description": "Tallest mountain in charted solar system", "media": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Olympus_Mons_alt.jpg/1024px-Olympus_Mons_alt.jpg", "copies": 1}}' --accountId $ID --deposit 10

返回内容如下

Transaction Id 9D4gQvxwb4MW82YdtRaimiM1aEVp1r69AqWmhzrG1c8G
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/9D4gQvxwb4MW82YdtRaimiM1aEVp1r69AqWmhzrG1c8G
{ token_id: '0',
  owner_id: 'pld2.testnet',
  metadata:
   { title: 'Olympus Mons',
     description: 'Tallest mountain in charted solar system',
     media:
      'https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Olympus_Mons_alt.jpg/1024px-Olympus_Mons_alt.jpg',
     media_hash: null,
     copies: 1,
     issued_at: null,
     expires_at: null,
     starts_at: null,
     updated_at: null,
     extra: null,
     reference: null,
     reference_hash: null },
  approved_account_ids: {} }

区块链浏览器tx:
near nft example
near nft example

上一篇:13. Roman to Integer


下一篇:Photoshop 偏暗人物的光亮粉色调