> 文章列表 > remix+infura.io

remix+infura.io

remix+infura.io

1. 首先去infura.io上注册帐号,创建自己的project,得到projectID和RPC endpoint

2. 在metamask的中设置-网络中,配置连接ropstep的RPC地址为infura.io中的RPC endpoint

3. 通过metamask申请测试ETH

4. RemixIDE激活WalletConnect插件,激活时,输入infura上注册的project ID,然后点击connect,选择一个钱包(说要选择WalletConnect,但是我选择钱包“metamask",后续也可以Deploy & Run)。参考:

walletconnect - Using Remix Web3 Provider with Infura - Ethereum Stack Exchange

5. 在RemixIDE中编写智能合约

6. RemixIDE部署合约时,选择网络环境为:WalletConnect

7. RemixIDE调用合约时,输入参数如果是数组,写法是:

["0x21DB4776B9F131fBC5B990e7BAcA48B6897c8cA7","0xDaf655C91C5ae499fa664c42BaFA59f1A21f94F4"]

或者:

 [1000000000000,1000000000000]

8. RemixIDE调用合约时,gasLimit缺省是自动估算的,如果想自己输入gasLimit,则在metamask的设置-高级,把高级gas控制打开

后记:

metamask中,以太坊的主网络,以及Ropsten测试网络,其实用的都是infura的endpoint。所以,如果只是编写、测试、部署智能合约,其实不必自己去申请infura的帐号、projectID和RPC endpoint,也不用RemixIDE也不用激活WalletConnect插件。用metamask连接Ropsten测试网络后,RemixIDE中,在Deploy & Run时,Environment选择选择Injected Web3即可。

当然,如果是写自己的dapp,比如钱包应用什么,又不想自己搭节点,那就注册个infura帐号最方便了。

RemixIDE中,Environment的说明:

JavaScript VM:
This is Remix’s own internal sandbox. It does not connect to MainNet, TestNet, or any private network. It’s an in-memory blockchain that can be used for simple testing and quick mining.

Injected Web3:
This is the option to use for the browser plugin (MetaMask). Here, you are telling Remix to defer all control of the blockchain integration to the MetaMask plugin. At this point, MetaMask controls which network you are connecting to.

In the plugin, you can connect to MainNet, Ropsten, Rinkeby, etc through Infura’s node network. In this case, you’re not running a node locally. MetaMask also has a localhost option where you can run your own node locally and MetaMask will send all transactions to it (this local network can be a private network using any node client or you can use a test blockchain like TestRPC).

Web3 Provider:
This allows you to enter a URL in Remix to connect to the blockchain. The most common setup here is to be running a local node and connecting to it through it’s IP/port.

This is pretty much the same as using MetaMask’s localhost option, but you’re just cutting the plugin out of being the middleman. Just like option #2, the network your connected to depends on how you’ve configured your local node (it can be main, test, private, etc.).