7

bep20 合约如何转移用户的bnb

 2 years ago
source link: https://learnblockchain.cn/question/2903
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

bep20 合约如何转移用户的bnb

bep20 合约如何转移用户的bnb

我现在想写一个自己的nft发售网站

需求就是用户访问网站,然后点击“铸造”按钮,这时候调用合约,实现两个功能:
1、转移用户1个bnb 到指定地址
2、转账成功后,给用户铸造nft

那么我这个合约该如何写,可以让用户授权使用用户的bnb资产,并将bnb转移到指定账户?

blockc0de - 自由职业者 2天前

合约方法使用 payable 修饰符,然后调用指定地址的 call 方法将 BNB 转移到指定账户。

function mint() external payable {
    (bool success, ) = toAddress.call{value: msg.value}("");
    require(success, "transfer-failed");
}

前端发送交易铸造 NFT 代币调用 eth_sendTransaction JSON-RPC 接口,参数 value 的值就是需要转移用户 BNB 的数量。

您需要登录后才可以回答问题,登录 或者 注册

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK