ReasonJun

Ethereum : Contract ABI 본문

Blockchain/Ethereum

Ethereum : Contract ABI

ReasonJun 2023. 10. 13. 17:06
728x90

The Contract Application Binary Interface (ABI) in the Ethereum Virtual Machine (EVM) is a standard way to interact with smart contracts. It defines the functions and data types that are available in a smart contract and which we can use to interact with that smart contract.

 

The ABI is a JSON file that contains information about the smart contract, such as the name of the contract, the functions that the contract provides, and the data types that the functions take and return. The ABI is used by wallets and other applications to interact with the smart contract.

 

To interact with a smart contract, you need to know the ABI of the contract. You can get the ABI of a contract from the contract's documentation or from a block explorer such as Etherscan.

 

Once you have the ABI of a contract, you can use it to call the contract's functions and to encode and decode data that is passed to and from the contract.

 

In EVM, Contract ABI is an interface that defines a standard system for calling functions and retrieving data from smart contracts.

 

For example, the following code shows how to call the set() function on the SimpleStorage contract from the previous example:

const ABI = [
    {
        "constant": false,
        "inputs": [
            {
                "name": "newData",
                "type": "uint256"
            }
        ],
        "name": "set",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    }
];

const contract = new web3.eth.Contract(ABI, "0x1234567890abcdef1234567890abcdef12345678");

contract.methods.set(10).send();

This code will call the set() function on the smart contract and store the value 10 in the storedData variable.

The ABI is an essential tool for interacting with smart contracts on the Ethereum blockchain. It allows us to call the functions of smart contracts and to encode and decode data that is passed to and from the contracts.

 

Here are some of the benefits of using the ABI in EVM:

  • Standardization: The ABI is a standardized way to interact with smart contracts. This makes it easier for wallets and other applications to interact with smart contracts.
  • Efficiency: The ABI allows us to encode and decode data that is passed to and from smart contracts in an efficient way.
  • Security: The ABI can help to improve the security of smart contracts by making it more difficult for malicious actors to exploit vulnerabilities in smart contracts.

Overall, the ABI is a powerful tool for interacting with smart contracts on the Ethereum blockchain. It is essential for developing and using smart contracts.

728x90

'Blockchain > Ethereum' 카테고리의 다른 글

Ethereum : EOA / CA  (0) 2023.10.18
Ethereum : Ghost Protocol (Greedy Heaviest Observed Subtree)  (0) 2023.10.13
Ethereum : Bytecode  (0) 2023.10.13
Ethereum : EVM 1.0 vs EVM 2.0  (0) 2023.10.13
Ethereum: What is EVM?  (0) 2023.10.13
Comments