来自以太坊和 Solana,我正在努力掌握 Avalanche 的 x 链。
我想做avm.createNFTAsset
,avm.mintNFT
我只能假设它是在 Avax NFT 工作室中手动创建和铸造家庭收藏品的程序化等价物。
我正在连接到一个 datahub figment x 链节点。
下面似乎有效,但我得到的最后一部分intNFTResponse {"jsonrpc":"2.0","error":{"code":-32000,"message":"provided addresses don't have the authority to mint the provided asset","data":null},"id":1}
我是否正确创建用户/密码?
此外,我如何在有效负载中设置图像元数据 - 就像 NFT 工作室一样?
如此迷茫 :(
const node = "https://avalanche--fuji--rpc.datahub.figment.io";
const apiKey = "<hidden>";
const username = "<hidden>";
const password = "<hidden>";
const test = async () => {
//get health of x chain node
const healthResponse = await axios.get(`${node}/ext/health`, {
headers: { Authorization: apiKey },
});
console.log(healthResponse.data);
//create user if not existing
const createUserReponse = await axios.post(
`${node}/ext/keystore`,
{
jsonrpc: "2.0",
id: 1,
method: "keystore.createUser",
params: {
username: username,
password: password,
},
},
{ headers: { Authorization: apiKey } }
);
console.log("createUserReponse", createUserReponse.data);
//list addresses for user
const listAddressesResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
id: createUserReponse.data.id,
method: "avm.listAddresses",
params: {
username: username,
password: password,
},
},
{ headers: { Authorization: apiKey } }
);
console.log("listAddressesResponse", listAddressesResponse.data);
let address;
if (listAddressesResponse.data.result.addresses.length == 0) {
//create address for user if not existing
const createAddressResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
method: "avm.createAddress",
params: {
username: username,
password: password,
},
id: createUserReponse.data.id,
},
{ headers: { Authorization: apiKey } }
);
console.log("createAddressResponse", createAddressResponse.data);
address = createAddressResponse.data.result.addresses[0];
} else {
address = listAddressesResponse.data.result.addresses[0];
}
console.log("proceeding with address", address);
getAllBalancesResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
method: "avm.getAllBalances",
params: {
address: address,
},
id: createUserReponse.data.id,
},
{ headers: { Authorization: apiKey } }
);
console.log(
"getAllBalancesResponse",
JSON.stringify(getAllBalancesResponse.data)
);
//create asset family with a base58 payload
const createNftAssetResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
id: 1,
method: "avm.createNFTAsset",
params: {
name: "BizNFTFamily",
symbol: "BTC",
minterSets: [
{
minters: [address],
threshold: 1,
},
],
username: username,
password: password,
},
id: createUserReponse.data.id,
},
{ headers: { Authorization: apiKey } }
);
console.log("createNftAssetResponse", createNftAssetResponse.data);
//new balance check
getAllBalancesResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
method: "avm.getAllBalances",
params: {
address: address,
},
id: createUserReponse.data.id,
},
{ headers: { Authorization: apiKey } }
);
console.log(
"getAllBalancesResponse",
JSON.stringify(getAllBalancesResponse.data)
);
//mint collectible in family
const mintNFTResponse = await axios.post(
`${node}/ext/bc/X`,
{
jsonrpc: "2.0",
id: createUserReponse.data.id,
method: "avm.mintNFT",
params: {
assetID: createNftAssetResponse.data.result.assetID,
payload: "2EWh72jYQvEJF9NLk",
to: address,
username: username,
password: password,
},
},
{ headers: { Authorization: apiKey } }
);
console.log("mintNFTResponse", JSON.stringify(mintNFTResponse.data));
};
return test()
.then()
.catch((err) => {
console.error(err.message);
});