NFT contract templates

Interact with smart contracts

To interact with a smart contract, your dapp needs the contract's:

Contract networkarrow-up-right

If you're not connected to the right network, you can't send transactions to your contract. Many dapp developers deploy their contract to a testnet first, in order to avoid potentially disastrous fees if something goes wrong during development and testing on Mainnet.

Regardless of which network you deploy your final dapp on, your users must be able to access it. Use the wallet_switchEthereumChainarrow-up-right and wallet_addEthereumChainarrow-up-right RPC methods to prompt the user to add a chain that you suggest, and switch to it using a confirmation dialogue.

Contract addressarrow-up-right

Every account in Ethereum has an address, whether it's an external key-pair account or a smart contract. For any smart contract library to communicate with your contracts, a smart contract must know the exact address.

Read about how to find a token contact addressarrow-up-right.

Contract ABIarrow-up-right

In Ethereum, the ABI specificationarrow-up-right is a way to encode the interface of a smart contract that's comprehensible to your user interface. The ABI is an array of method-describing objects, and when you feed this and the address into a contract-abstraction library, the ABI tells those libraries about what methods to provide, and how to compose transactions to call those methods.

Example libraries include:

Contract bytecodearrow-up-right

If your dapp publishes a new pre-compiled smart contract, it might need to include some bytecode. You don't know the contract address in advance; you must publish the contract, watch for the transaction to be processed, and then extract the final contract's address from the completed transaction.

If you publish a contract from bytecode, you still need an ABIarrow-up-right to interact with it. The bytecode doesn't describe how to interact with the final contract.

Contract source codearrow-up-right

If your dapp allows users to edit smart contract source code and compile it, similar to Remixarrow-up-right, you can import a whole compiler. You derive your bytecode and ABI from that source code, and eventually derive the contract's address from the completed transaction, where that bytecode is published.

Last updated