Initialize the DApp
Once you have a basic development environment, you can start interacting with some smart contracts. When communicating with smart contracts, the following are important information that you must read in detail
Contract Network
If not connected to the correct network, you will not have any possibility to send transactions to your contract, so make sure you have this right! Many DApp developers choose to deploy their contracts to the testnet first to avoid potentially catastrophic fees if problems arise during mainnet development and testing.
No matter which network you deploy your final DApp on, it should be accessible to your users. TokenPocket Extension provides wallet_switchEthereumChain and wallet_addEthereumChain, which allow you to prompt the user to add your suggested chain and switch to it using a confirmation dialog.
Contract address
Every account in Ethereum has an address, be it an external key pair account or a smart contract. In order for any smart contract library to communicate with your contract, they need to know its exact address. If you deployed the contract, you probably know how to find the address.。
Contract ABI
As for Ethereum, it is to code the interface of a smart contract in a way that the user interface can understand. It's a set of objects describing methods, and when you enter this and address into a contract abstraction library, the ABI tells those libraries which methods to provide, and how to compose transactions to call those methods.
Example libraries include:
Contract Bytecode
If you are going to publish a precompiled new smart contract for your web application, it may need to include some bytecode. In this case, you don't know the contract address ahead of time, but you have to publish and observe the transaction to be processed, and then retrieve the final contract address from the completed transaction.
If publishing a contract from bytecode
, you still need an ABI if you want to interact with it! The bytecode
does not describe how to interact with the final contract.
Contract source code
Sometimes your website will allow users to edit the smart contract source code and compile it, for example, you can use Remix to import the entire compiler. In this case, you will derive your bytecode
and ABI from this source code, and eventually get the address of the contract from the completed transaction, that is where the bytecode
was published.
Last updated