【发布时间】:2022-08-12 18:27:29
【问题描述】:
我想用 js 将 nft 从 \'AdminWallet\' 转移给用户。 我有一个包含所有 nft 的 AdminWallet。 现在我希望用户能够通过按下按钮来认领他们。
我正在使用 js 代码来完成此操作。
我有以下代码:
const tx = {
from: PUBLIC_KEY,
to: user_address,
nonce: nonce,
gas: 500000,
data: contract.methods.safeTransferFrom(PUBLIC_KEY, user_address, \"1\").encodeABI(),
chain: \"rinkeby\",
hardfork: \"petersburg\"
}
const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY)
signPromise
.then((signedTx) => {
web3.eth.sendSignedTransaction(
signedTx.rawTransaction,
function(err, hash) {
if (!err) {
console.log(
\"The hash of your transaction is: \",
hash,
)
} else {
console.log(
\"Something went wrong when submitting your transaction:\",
err
)
}
}
)
})
.catch((err) => {
console.log(\" Promise failed:\", err)
})
所以我在这里尝试做的是从 PUBLIC_KEY 地址上的 \'AdminWallet\' 发送一个带有 tokenid \'1\' 的 nft 到 user_address。
如果我在没有 signtransaction() 的情况下这样做,我会调用以下命令:
contract.methods.safeTransferFrom(PUBLIC_KEY, user_address, \"1\").send({ from: PUBLIC_KEY})
从我能找到的 signTransaction() 调用 tx 数据的 .Call() 。 如果我想用我原来的方式传输 nft,我必须调用 .send() 函数。
无论如何调用 .send() 函数来签署自动签署交易?
标签: javascript blockchain web3js nft