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 써서 로그 기록으로 남기기