일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 러스트 기초 학습
- ambiguous function description
- 계정추상화
- ethers v6
- vue기초
- 체인의정석
- erc4337 contract
- 스마트컨트렉트 함수이름 중복 호출
- 티스토리챌린지
- chainlink 설명
- 컨트렉트 배포 자동화
- 스마트컨트렉트테스트
- ethers
- 러스트 기초
- 오블완
- ethers type
- rust 기초
- erc4337
- multicall
- 머신러닝기초
- 스마트컨트렉트 예약어 함수이름 중복
- ethers typescript
- 러스트기초
- ethers websocket
- git rebase
- 스마트 컨트렉트 함수이름 중복
- SBT표준
- 컨트렉트 동일한 함수이름 호출
- Vue
- Vue.js
- Today
- Total
체인의정석
DelegateCall에서 값을 가져오는 케이스 본문
Hardhat Test returns transaction instead of return value
I just came from truffle to hardhat. Like the title says, I have a return value (address) of a contract and getting the transaction back. Any idea what I can do about that? it("Check all teste...
ethereum.stackexchange.com
1. 조회함수의 경우
To get the return value you should add callStatic to it.
> const shareTokenAddress = await liqminter.connect(actorA).callStatic.createPair([...])
callStatic is a read-only operation and will not consume any Ether. It simulates what would happen in a transaction, but discards all the state changes when it is done.
2. 이벤트를 쓰는 경우
const tx = await contract.transfer(...args); // 100ms
const rc = await tx.wait(); // 0ms, as tx is already confirmed
const event = rc.events.find(event => event.event === 'Transfer');
const [from, to, value] = event.args;
console.log(from, to, value);
Check it out https://ethereum.stackexchange.com/a/119856/92472
이벤트를 써서 체크하는 방법이 더 좋아보긴 한다.
Return value from a deployed smart contract, via a smart contract, to a smart contract
I am trying to return a value using a function of a deployed smart contract on the blockchain. pragma solidity 0.6.2; contract Caller { address cont; function changeAdd(address _change) ...
stackoverflow.com
Do you try to use abi.decode function of Solidity.
In the below example, contract B calls setName of contract A, then decodes the result by using abi.decode function.
contract A {
string public name;
constructor(string memory tokenName) public {
name = tokenName;
}
function setName(string memory newName) public returns ( string memory){
name = newName;
return newName;
}
}
contract B {
event Log(string msg);
string public myName;
function call(address addr, string memory newName) public {
bytes memory payload = abi.encodeWithSignature("setName(string)", newName);
(bool success, bytes memory result)= addr.call(payload);
// Decode data
string memory name = abi.decode(result, (string));
myName = name;
emit Log(name);
}
}
3. decode 써서 로그 기록으로 남기기
'블록체인 > Solidity' 카테고리의 다른 글
이벤트 로그에 구조체 데이터 넣기, 이벤트 로그 작성하기 (0) | 2022.07.13 |
---|---|
delegateCall에서의 상태변화 가능여부 및 사용하면 안되는 이유 (0) | 2022.07.08 |
하나의 컨트렉트를 여러개로 분리해서 만들 때의 주의 사항 (0) | 2022.07.07 |
Warning: Return value of low-level calls not used (0) | 2022.07.06 |
Solidity constants vs immutable 차이 (0) | 2022.07.06 |