diff --git a/src/contract.js b/src/contract.js index 7b320486..0e97dddd 100644 --- a/src/contract.js +++ b/src/contract.js @@ -1,3 +1,4 @@ +import { Address } from './address'; import { Operation } from './operation'; import xdr from './xdr'; import { StrKey } from './strkey'; @@ -51,6 +52,14 @@ export class Contract { } } + /** + * Returns the address of this contract as an Address type. + * @returns {Address} + */ + address() { + return Address.contract(this._id); + } + /** * Returns an operation that will invoke this contract call. * diff --git a/test/unit/contract_test.js b/test/unit/contract_test.js index a816ac87..9d0d9eac 100644 --- a/test/unit/contract_test.js +++ b/test/unit/contract_test.js @@ -19,6 +19,14 @@ describe('Contract', function () { }); }); + describe('address', function () { + it('returns the contract address', function () { + let contractId = '0'.repeat(63) + '1'; + let contract = new StellarBase.Contract(contractId); + expect(contract.address().toBuffer().toString('hex')).to.equal(contractId); + }); + }); + describe('getFootprint', function () { it('includes the correct contract code footprint', function () { let contractId = '0'.repeat(63) + '1';