简体   繁体   English

如何从node.js在智能合约中创建令牌?

[英]How can I create tokens in smart contract from node.js?

I have followed the tutorial at https://www.ethereum.org/token to deploy a contract with a certain number of tokens. 我已按照https://www.ethereum.org/token上的教程进行操作,以部署具有一定数量令牌的合同。 I have also implemented functions to mint new tokens or burn existing tokens. 我还实现了铸造新令牌或刻录现有令牌的功能。

However, I want to list tokens, create tokens, and delete tokens from a node.js project. 但是,我想列出令牌,创建令牌以及从node.js项目中删除令牌。 I don't really understand how this can be done since it costs gas/ether to communicate with the Ethereum blockchain. 我真的不明白该怎么办,因为与以太坊区块链进行通信需要花费大量的汽油/乙醚。

Is it possible to initiate actions in the blockchain from "off-chain" projects? 是否可以从“链下”项目在区块链中启动动作? Can I use web3 or truffle for this purpose? 我可以web3使用web3truffle吗? I imagine that it might be possible to just store a lot of ether on an account and then just tell the smart contract to use ether from this account to update tokens in the smart contract? 我想也许可以在一个帐户中存储大量以太币,然后告诉智能合约使用该帐户中的以太币来更新智能合约中的令牌?

I have seen projects where I can communicate with the contracts using MetaMask, but I want to develop a project that doesn't require the user to have a wallet at all. 我已经看到了可以使用MetaMask与合同进行通信的项目,但是我想开发一个完全不需要用户拥有钱包的项目。

Any modification to the Ethereum Blockchain will cost you gas, so yeah creating new coins will cost you money. 以太坊区块链的任何修改都将花费您汽油,因此,是的,创建新硬币将花费您金钱。

Listing them is free, you have the ability, throught web3, to list informations about blocks, accounts or smart contracts. 列出它们是免费的,您可以通过web3列出有关冻结,账户或智能合约的信息。

So if you want to list coins, you can make a scraper that goes through all the Blockchain and detects ERC20 Contracts (take a look at how EVM bytecode works and how you can identify specific methods defined in protocols like ERC20 only from the bytecode) for free. 因此,如果要列出硬币,则可以制作一个刮板,遍历所有区块链并检测ERC20合同(看看EVM字节码如何工作,以及如何仅从字节码中识别协议(如ERC20)中定义的特定方法)自由。

Remember: Only state alteration costs gas ! 切记:只有状态变更会花费汽油!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM