Wallet Setup
Set up a wallet for contract deployment and execution
Key Management with MetaMask
Developers can manage Ethereum wallet private keys using the MetaMask browser add-on.
MetaMask is a non-custodial wallet. The user's private key is encoded with the mnemonic phrase and stored in user's local browser. Once lost, the user can no longer control the savings or restore access to the wallet. MetaMask communicates with Ethereum Ledger via Infura. Please refer to the MetaMask website for more details.
Initialize Web3
First, install the following in your dApp:
Create a new file, name it web3.js and insert the following code in it:
To put it simply, you can inject the global object ethereum
if you have added MetaMask to Chrome.
Next, import the code as below:
Call the function:
Set up Account
We need an account from the web3 instance we created above to send transactions.
The getAccounts()
function returns all the user’s Metamask accounts, whileaccounts[0]
is the one currently selected by the user.
Initialize Contract
Initialize your contract after completing above steps.
Call Functions
Now you can call any function by directly interacting with the instantiated contract. Please note that:
Functions that do not alter the state of the contract are call()
functions. Below is an example of calling a call()
function:
Functions that alter the state of the contract are send()
functions. Below is an example of calling a send()
function:
Move Assets from Ethereum to Ontology
Ontology supports developers to conduct cross-chain asset transfer using PolyBridge.
Last updated