Once you’ve either imported particular contracts manually or simply installed filecoin-solidity using npm, create a callable method to access the built-in actor methods the way you normally would in a Solidity smart contract. Working examples of smart contracts that call built-in actor methods are available below.
The following example imports the Storage market actor library and creates a callable method for each of the available actor methods. For the full code, see the GitHub repository.
pragmasolidity ^0.8.17;import"../MinerAPI.sol";import"../types/MinerTypes.sol";contract MinerApiTest {functionget_owner(CommonTypes.FilActorId target) publicreturns (MinerTypes.GetOwnerReturnmemory) {return MinerAPI.getOwner(target); }functionchange_owner_address(CommonTypes.FilActorId target,CommonTypes.FilAddressmemory addr) public { MinerAPI.changeOwnerAddress(target, addr); } function is_controlling_address(CommonTypes.FilActorId target, CommonTypes.FilAddress memory addr) public returns (bool) {
return MinerAPI.isControllingAddress(target, addr); }functionget_sector_size(CommonTypes.FilActorId target) publicreturns (uint64) {return MinerAPI.getSectorSize(target); }functionget_available_balance(CommonTypes.FilActorId target) publicreturns (CommonTypes.BigIntmemory) {return MinerAPI.getAvailableBalance(target); } function get_vesting_funds(CommonTypes.FilActorId target) public returns (MinerTypes.GetVestingFundsReturn memory) {
return MinerAPI.getVestingFunds(target); } function change_beneficiary(CommonTypes.FilActorId target, MinerTypes.ChangeBeneficiaryParams memory params) public {
return MinerAPI.changeBeneficiary(target, params); }functionget_beneficiary(CommonTypes.FilActorId target) publicreturns (MinerTypes.GetBeneficiaryReturnmemory) {return MinerAPI.getBeneficiary(target); } function change_worker_address(CommonTypes.FilActorId target, MinerTypes.ChangeWorkerAddressParams memory params) public {
MinerAPI.changeWorkerAddress(target, params); }functionchange_peer_id(CommonTypes.FilActorId target,CommonTypes.FilAddressmemory newId) public { MinerAPI.changePeerId(target, newId); } function change_multiaddresses(CommonTypes.FilActorId target, MinerTypes.ChangeMultiaddrsParams memory params) public {
MinerAPI.changeMultiaddresses(target, params); }functionrepay_debt(CommonTypes.FilActorId target) public { MinerAPI.repayDebt(target); }functionconfirm_change_worker_address(CommonTypes.FilActorId target) public { MinerAPI.confirmChangeWorkerAddress(target); }functionget_peer_id(CommonTypes.FilActorId target) publicreturns (CommonTypes.FilAddressmemory) {return MinerAPI.getPeerId(target); }functionget_multiaddresses(CommonTypes.FilActorId target) publicreturns (MinerTypes.GetMultiaddrsReturnmemory) {return MinerAPI.getMultiaddresses(target); } function withdraw_balance(CommonTypes.FilActorId target, CommonTypes.BigInt memory amount) public returns (CommonTypes.BigInt memory) {
return MinerAPI.withdrawBalance(target, amount); }}
Call the storage power actor
The following example imports the Storage power actor library and creates a callable method for each of the available actor methods. For the full code, see the GitHub repository.
The following example imports the verified registry actor library and creates a callable method for each of the available actor methods. For the full code, see the GitHub repository.
pragmasolidity ^0.8.17;import"../types/VerifRegTypes.sol";import"../types/CommonTypes.sol";import"../VerifRegAPI.sol";contract VerifRegApiTest { function get_claims(VerifRegTypes.GetClaimsParams memory params) public returns (VerifRegTypes.GetClaimsReturn memory) {
return VerifRegAPI.getClaims(params); }functionadd_verified_client(VerifRegTypes.AddVerifiedClientParamsmemory params) public { VerifRegAPI.addVerifiedClient(params); }functionremove_expired_allocations(VerifRegTypes.RemoveExpiredAllocationsParamsmemory params ) publicreturns (VerifRegTypes.RemoveExpiredAllocationsReturnmemory) {return VerifRegAPI.removeExpiredAllocations(params); } function extend_claim_terms(VerifRegTypes.ExtendClaimTermsParams memory params) public returns (CommonTypes.BatchReturn memory) {
return VerifRegAPI.extendClaimTerms(params); } function remove_expired_claims(VerifRegTypes.RemoveExpiredClaimsParams memory params) public returns (VerifRegTypes.RemoveExpiredClaimsReturn memory) {
return VerifRegAPI.removeExpiredClaims(params); }}