일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 머신러닝기초
- ethers
- Vue
- erc4337 contract
- 티스토리챌린지
- 체인의정석
- 컨트렉트 동일한 함수이름 호출
- ethers type
- erc4337
- Vue.js
- ethers v6
- 컨트렉트 배포 자동화
- chainlink 설명
- 러스트 기초 학습
- 스마트컨트렉트 예약어 함수이름 중복
- 계정추상화
- ethers websocket
- 스마트컨트렉트테스트
- 러스트 기초
- 러스트기초
- 오블완
- 스마트컨트렉트 함수이름 중복 호출
- rust 기초
- ethers typescript
- 스마트 컨트렉트 함수이름 중복
- git rebase
- ambiguous function description
- SBT표준
- vue기초
- multicall
- Today
- Total
체인의정석
[솔리디티 오버로딩 함수 호출 방법] & 솔리디티 오버로딩에 대한 에러Solidity TypeError: ambiguous function description (i.e. matches 및 해결 방안 본문
[솔리디티 오버로딩 함수 호출 방법] & 솔리디티 오버로딩에 대한 에러Solidity TypeError: ambiguous function description (i.e. matches 및 해결 방안
체인의정석 2024. 5. 7. 15:53TypeError: ambiguous function description (i.e. matches
해당 에러는 solidity에서 동일한 함수 이름으로 2개의 함수를 작성했을 때 어떤 함수를 부르는지 정확히 명시하지 못해서 나는 에러이다. 솔리디티에서는 오버로딩이 가능하여 동일한 이름으로 2개의 함수를 만들 수는 있지만 변수명과 타입을 다르게 해서 만들어 줘야한다.
오픈제플린과 같은 외부 라이브러리를 써서 여러 컨트렉트를 상속관계로 짜서 만들 때 이미 구현된 함수를 다시 한번 작성하는 경우 위와 같은 에러가 종종 발생하기도 한다.
https://github.com/ethers-io/ethers.js/issues/4296
"ambiguous function description" error when contract has functions with same names · Issue #4296 · ethers-io/ethers.js
Ethers Version 6.7.0 Search Terms No response Describe the Problem I added function burn(address account, uint256 amount) public onlyRole(BURNER_ROLE) to an ERC20 contract. It compiles successfully...
github.com
만약 같은 함수 이름에 변수명만 다르게 했다면 ethers를 써서 함수를 호출할 때 오버로딩을 한 함수에 맞추어서 호출을 하지 않은 것이다.
ethers - call an overloaded function with a specific signer
Connecting a specific signer to a contract object in Ethers is easy: // assuming a signer called 'user' and a contract called 'Foo' with function 'bar' await Foo.connect(user).bar(); There's also ...
ethereum.stackexchange.com
await NFT.connect(sender)['safeTransferFrom(address,address,uint256)'](
sender.address,
recipient.address,
ethers.BigNumber.from("1")
);
다음과 같이 트랜잭션을 보내려는 함수의 파라미터 값을 ethers에서 정확히 명시해서 넘겨야 한다. 해당 문제는 아래 링크에 더 많은 예시가 있다.
https://github.com/ethers-io/ethers.js/issues/407
Contract with function overloading · Issue #407 · ethers-io/ethers.js
Hi, A contract that I'm testing has different interfaces for same function name: // Order that appers on ABI initialize(string _name, string _symbol); initialize(string _name, string _symbol, addre...
github.com
contract
pragma solidity ^0.5.0;
contract SampleContract {
function overloading() public pure returns(uint) {
return 1;
}
function overloading(string memory a) public pure returns(uint) {
return 2;
}
function overloading(string memory a, string memory b) public pure returns(uint) {
return 3;
}
}
test code
describe.only("", () => {
// OK
it("should call overloading functions - web3js", async function() {
const sampleContractWeb3 = new web3.eth.Contract(abi, address);
const f1 = await sampleContractWeb3.methods.overloading().call();
const f2 = await sampleContractWeb3.methods.overloading("a").call();
const f3 = await sampleContractWeb3.methods.overloading("a", "b").call();
expect(f1).to.equal("1");
expect(f2).to.equal("2");
expect(f3).to.equal("3");
});
// OK
it("should call overloading functions - ethers", async function() {
const provider = new ethers.providers.JsonRpcProvider();
const sampleContractEthers = new ethers.Contract(address, abi, provider);
const f1 = await sampleContractEthers["overloading()"]();
const f2 = await sampleContractEthers["overloading(string)"]("a");
const f3 = await sampleContractEthers["overloading(string,string)"](
"a",
"b"
);
expect(f1.toNumber()).to.equal(1);
expect(f2.toNumber()).to.equal(2);
expect(f3.toNumber()).to.equal(3);
});
// FAIL
it("should call overloading functions - ethers", async function() {
const provider = new ethers.providers.JsonRpcProvider();
const sampleContractEthers = new ethers.Contract(address, abi, provider);
const f1 = await sampleContractEthers.overloading(); // Error: incorrect number of arguments
const f2 = await sampleContractEthers.overloading("a");
const f3 = await sampleContractEthers.overloading("a", "b");
expect(f1.toNumber()).to.equal(1);
expect(f2.toNumber()).to.equal(2);
expect(f3.toNumber()).to.equal(3);
});
});
'블록체인 > Solidity' 카테고리의 다른 글
Tally와 호환되는 DAO 컨트렉트 (timelock & erc20) 구현하기 (0) | 2024.08.09 |
---|---|
다양한 체인에 동일한 주소로 배포가 가능한 Create3 자세히 살펴보기 (1) | 2024.07.02 |
Lens, Gateway 등 조회 컨트렉트를 만들 때의 유의점 (0) | 2024.04.26 |
ERC721,1155 receiver (0) | 2024.04.05 |
create2 & create3에서의 Owner msg.sender 처리 (0) | 2024.03.28 |