일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Firebase authentication android apple login
- 소개팅앱 만들기
- Supabase edge function
- 로컬 서버 접속
- supabase edge function deploy error supabaseurl is required
- Android apple login
- Firebase authentication apple login
- Android apple login identifier
- 주 4일 근무제 log
- 주 4일 근무제
- Firebase authentication android apple login setting
- Firebase authentication apple login 최신
- Spring LocalDateTime response array
- Stomp socket connection event
- supabase storage feature not enabled for this tenant
- Android apple login 인증서 설정
- no such module '__ObjC'
- Spring google SMTP settings
- 소개팅앱 만들기 stomp
- 주 4일 근무제 경험담
- stable-diffusion-webui local 네트워크에서 접속
- Spring boot swagger blank screen
- stable-diffusion-webui local 접속
- supabase edge function deploy error
- Stomp user connection event
- invite user for supabase project
- 소개팅앱 만들기 flutter
- supabase storage public url not working
- Supabase edge function insert data
- DT_TOOLCHAIN_DIR cannot be used
Archives
- Today
- Total
꿀맛코딩
ABI(Application Binary interface) 구현 방법 본문
이번에는 웹에서 스마트 컨트랙트의 함수를 실행 시켜 볼거에요.
실행에 대한 결과를 말하면
test.sol 의 renderTest함수를 실행해서 String 값을 가져오고
http://127.0.0.1:8080/test 접속시
해당 함수 실행 값을 가져올거에요.
시작해 볼게요.
아래의 코드들을 프로젝트에 옮겨 주세요.
1. test.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
contract Test {
function renderTest () public pure returns (string memory greeting) {
greeting = "Hello World!";
}
}
2. index.js
const express = require('express');
const app = express();
const port = 8080;
const Contract = require('web3-eth-contract');
async function test() {
try {
const abi = [
{
"inputs": [],
"name": "renderTest",
"outputs": [
{
"internalType": "string",
"name": "greeting",
"type": "string"
}
],
"stateMutability": "pure",
"type": "function"
}
];
const address = '배포된 스마트 컨트랙트 주소 복사';
Contract.setProvider('http://127.0.0.1:7545');
const contract = new Contract(abi, address);
const result = await contract.methods.renderTest().call();
console.log(result);
return result;
} catch (e) {
console.log(e);
return e;
}
}
app.get('/test', (req, res) => {
test().then( (result) => {
res.send(result);
})
})
app.listen(port, () => {
console.log('Listening...');
});
3. 위의 코드들을 입력후 Remix 에 접속해서 Deploy를 해줘요
그리고 아래 그림의 빨간색 네모 박스의 컨트랙트 주소 값을 복사해주세요.
해당 값을 2번의 address 변수 에 넣어서
index.js 파일을 실행 시켜주면 돼요.
터미널에서
node index.js
를 입력하여 실행해 주세요.
4. 정상 적으로 실행 되었다면 접속시 (http://127.0.0.1:8080/test) 아래와 같은 화면이 나올거에요
반응형
'공부방 > 블록체인' 카테고리의 다른 글
ERC20 코드 분석 1 (0) | 2023.04.27 |
---|---|
솔리디티 문법 (0) | 2023.04.24 |
Remix 가나슈 연결 (0) | 2023.04.21 |
Web 3 js 를 이용한 지갑 잔액 확인 (0) | 2023.04.21 |
Comments