javascript Web3 라이브러리를 이용해서 contract 함수 호출하려고 할 때 함수가 호출 안되는 에러가 있었음.
contract 호출 시 send() & call() 함수를 마지막에 붙여서 사용해야 함. (아래 함수 참고)
this.createLendInfo = async (nftId) => {
const txResult = await lendingPoolContract.methods.createLendInfo(nftId).call();
return txResult;
}
this.lend = async (lendInfo) => {
const txResult = await lendingPoolContract.methods.lend(lendInfo).send({from: account.address});
return txResult;
}
onlyOwner만 호출할 수 있는 함수가 있었음. 그런데 분명 Owner가 맞는데 owner가 아니라는 에러가 발생함.
⇒ 위의 Web3.0 라이브러리로 Contract call Method만 호출해도 msg.sender가 사용자로 자동 설정되는 줄 알았음.
⇒ send() 함수를 써야지 msg.sender가 해당 사용자의 주소로 설정됨. 즉, call은 그저 get 함수로서 msg.sender에 아무런 값이 들어가지 않게됨!
this.lend = async (lendInfo) => {
const txResult = await lendingPoolContract.methods.lend(lendInfo)
.send({from: account.address});
return txResult;
}